check if application exists before switching to it
package application
import (
+ "fmt"
+
"github.com/pkg/errors"
"github.com/redhat-developer/ocdev/pkg/config"
"github.com/redhat-developer/ocdev/pkg/occlient"
@@ -169,6 +171,24 @@ func SetCurrent(name string) error {
return errors.Wrap(err, "unable to get active application")
}
+ apps, err := List()
+ if err != nil {
+ return errors.Wrap(err, "unable to get active application")
+
+ }
+ // check if application exists
+ found := false
+ for _, app := range apps {
+
+ if app.Name == name {
+ found = true
+ break
+ }
+ }
+ if !found {
+ return fmt.Errorf("application %s doesn't exist", name)
+ }
+
cfg, err := config.New()
if err != nil {
return errors.Wrap(err, "unable to get active application")
