Skip to content

Commit

Permalink
resolved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrisyhjiang committed Jun 27, 2024
1 parent a57cd49 commit e4a2361
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
12 changes: 4 additions & 8 deletions src/cmd/cli/command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,16 +509,12 @@ Generate will write files in the current folder. You can edit them and then depl

if sample != "" {
qs = qs[1:] // user picked a sample, so we skip the description question
sampleExists := false
for _, s := range sampleList {
if s.Name == sample {
sampleExists = true
break
}
}
sampleExists := slices.ContainsFunc(sampleList, func(s cli.Sample) bool {
return s.Name == sample
})

if !sampleExists {
return errors.New("sample not found")
return cli.ErrSampleNotFound
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/pkg/cli/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"compress/gzip"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"os"
Expand All @@ -15,6 +16,8 @@ import (
"github.com/DefangLabs/defang/src/pkg/term"
)

var ErrSampleNotFound = errors.New("sample not found")

type Sample struct {
Name string `json:"name"`
Title string `json:"title"`
Expand Down Expand Up @@ -102,7 +105,7 @@ func InitFromSamples(ctx context.Context, dir string, names []string) error {
}
}
if !sampleFound {
return fmt.Errorf("sample not found")
return ErrSampleNotFound
}
return nil
}
Expand Down

0 comments on commit e4a2361

Please sign in to comment.