Skip to content

Commit 87e270f

Browse files
edwardrfedw-defang
andauthored
Use containsFunc instead of intermediary slice (#571)
* Use containsFunc instead of intermediary slice * Change node and golang back --------- Co-authored-by: Edward J <[email protected]>
1 parent 28767cb commit 87e270f

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/cmd/cli/command/commands.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,8 @@ var generateCmd = &cobra.Command{
445445
if sample == "" {
446446
if err := survey.AskOne(&survey.Select{
447447
Message: "Choose the language you'd like to use:",
448-
Options: []string{"JavaScript", "Go", "Python"},
449-
Default: "JavaScript",
448+
Options: []string{"Nodejs", "Golang", "Python"},
449+
Default: "Nodejs",
450450
Help: "The project code will be in the language you choose here.",
451451
}, &language); err != nil {
452452
return err
@@ -457,15 +457,10 @@ var generateCmd = &cobra.Command{
457457
} else if len(sampleList) > 0 {
458458
const generateWithAI = "Generate with AI"
459459

460-
lang := strings.ToLower(language)
461460
sampleNames := []string{generateWithAI}
462461
sampleDescriptions := []string{"Generate a sample from scratch using a language prompt"}
463462
for _, sample := range sampleList {
464-
sampleLangs := make([]string, len(sample.Languages))
465-
for _, l := range sample.Languages {
466-
sampleLangs = append(sampleLangs, strings.ToLower(l))
467-
}
468-
if slices.Contains(sampleLangs, lang) {
463+
if slices.ContainsFunc(sample.Languages, func(l string) bool { return strings.EqualFold(l, language) }) {
469464
sampleNames = append(sampleNames, sample.Name)
470465
sampleDescriptions = append(sampleDescriptions, sample.ShortDescription)
471466
}

0 commit comments

Comments
 (0)