From c5e6fa40bf116293e0df33e6eaa58c4b50ad83ba Mon Sep 17 00:00:00 2001 From: mik-dass Date: Fri, 23 Jul 2021 12:26:49 +0530 Subject: [PATCH] Modifies the error message to list the available starters --- pkg/component/starter_project.go | 8 ++++++-- tests/integration/devfile/cmd_devfile_create_test.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/component/starter_project.go b/pkg/component/starter_project.go index 99ccbf0e033..1067e36ac47 100644 --- a/pkg/component/starter_project.go +++ b/pkg/component/starter_project.go @@ -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" @@ -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) } } diff --git a/tests/integration/devfile/cmd_devfile_create_test.go b/tests/integration/devfile/cmd_devfile_create_test.go index 673ab5d32be..c78ba8117a2 100644 --- a/tests/integration/devfile/cmd_devfile_create_test.go +++ b/tests/integration/devfile/cmd_devfile_create_test.go @@ -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"}) }) })