Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifies the error message to list the available starters #4935

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pkg/component/starter_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"

devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
parsercommon "github.com/devfile/library/pkg/devfile/parser/data/v2/common"
Expand Down Expand Up @@ -53,17 +54,20 @@ func GetStarterProject(projects []devfilev1.StarterProject, projectPassed string
project = &projects[0]
log.Warning("There are multiple projects in this devfile but none have been specified in --starter. Downloading the first: " + project.Name)
} else { //If the user has specified a project
var availableNames []string

projectFound := false
for indexOfProject, projectInfo := range projects {
availableNames = append(availableNames, projectInfo.Name)
if projectInfo.Name == projectPassed { //Get the index
project = &projects[indexOfProject]
projectFound = true
break
}
}

if !projectFound {
return nil, errors.Errorf("the project: %s specified in --starter does not exist", projectPassed)
availableNamesString := strings.Join(availableNames, ",")
return nil, errors.Errorf("the project: %s specified in --starter does not exist, available projects: %s", projectPassed, availableNamesString)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/devfile/cmd_devfile_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ var _ = Describe("odo devfile create command tests", func() {
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile.yaml"), filepath.Join(commonVar.Context, "devfile.yaml"))
output := helper.Cmd("odo", "create", "nodejs", "--starter=invalid-project-name").ShouldFail().Err()
expectedString := "the project: " + invalidProjectName + " specified in --starter does not exist"
helper.MatchAllInOutput(output, []string{expectedString})
helper.MatchAllInOutput(output, []string{expectedString, "available projects", "nodejs-starter"})
})
})

Expand Down