Fixes the issue of switching to a non-existing component using set command
Uses the exists function to check if the component exists in the current application or not.
@@ -8,6 +8,7 @@ import (
"github.com/redhat-developer/odo/pkg/project"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
+ "os"
)
// componentCmd represents the component command
@@ -64,6 +65,15 @@ var componentSetCmd = &cobra.Command{
checkError(err, "")
projectName := project.GetCurrent(client)
+ exists, err := component.Exists(client, args[0], applicationName, projectName)
+ if err != nil {
+ checkError(err, "")
+ }
+ if !exists {
+ fmt.Printf("Component %s does not exist in the current application\n", args[0])
+ os.Exit(1)
+ }
+
err = component.SetCurrent(client, args[0], applicationName, projectName)
checkError(err, "")
fmt.Printf("Switched to component: %v\n", args[0])
