Skip to content

Commit

Permalink
small change
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrisyhjiang committed Jun 27, 2024
1 parent b974196 commit 74f5c34
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/pkg/cli/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ func InitFromSamples(ctx context.Context, dir string, names []string) error {
tarReader := tar.NewReader(tarball)
term.Info("Writing files to disk...")

found := make(map[string]bool)
for _, name := range names {
found[name] = false
}
sampleFound := false

for {
h, err := tarReader.Next()
Expand All @@ -89,6 +86,7 @@ func InitFromSamples(ctx context.Context, dir string, names []string) error {
}
prefix := fmt.Sprintf("%s-%s/samples/%s/", repo, branch, name)
if base, ok := strings.CutPrefix(h.Name, prefix); ok && len(base) > 0 {
sampleFound = true
fmt.Println(" -", base)
path := filepath.Join(dir, subdir, base)
if h.FileInfo().IsDir() {
Expand All @@ -103,13 +101,9 @@ func InitFromSamples(ctx context.Context, dir string, names []string) error {
}
}
}

for _, name := range names {
if !found[name] {
return fmt.Errorf("sample not found")
}
if !sampleFound {
return fmt.Errorf("sample not found")
}

return nil
}
func createFile(base string, h *tar.Header, tarReader *tar.Reader) error {
Expand Down

0 comments on commit 74f5c34

Please sign in to comment.