Skip to content

Commit

Permalink
Validate the '--no-commands' flag in the CLI
Browse files Browse the repository at this point in the history
For example, it should not be possible to call it alongside '--build-command' or '--run-command',
because we won't be able to know what to do.
  • Loading branch information
rm3l committed Jun 2, 2023
1 parent 151712e commit ffbea2c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pkg/odo/cli/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,17 @@ func (o *DevOptions) Complete(ctx context.Context, cmdline cmdline.Cmdline, args

func (o *DevOptions) Validate(ctx context.Context) error {
devfileObj := *odocontext.GetEffectiveDevfileObj(ctx)
if !o.debugFlag && !libdevfile.HasRunCommand(devfileObj.Data) {
return clierrors.NewNoCommandInDevfileError("run")
}
if o.debugFlag && !libdevfile.HasDebugCommand(devfileObj.Data) {
return clierrors.NewNoCommandInDevfileError("debug")
if o.noCommandsFlag {
if o.buildCommandFlag != "" || o.runCommandFlag != "" {
return errors.New("--no-commands cannot be used with --build-command or --run-command")
}
} else {
if !o.debugFlag && !libdevfile.HasRunCommand(devfileObj.Data) {
return clierrors.NewNoCommandInDevfileError("run")
}
if o.debugFlag && !libdevfile.HasDebugCommand(devfileObj.Data) {
return clierrors.NewNoCommandInDevfileError("debug")
}
}

platform := fcontext.GetPlatform(ctx, commonflags.PlatformCluster)
Expand Down

0 comments on commit ffbea2c

Please sign in to comment.