Skip to content

Commit

Permalink
Fix functions names
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Oct 4, 2022
1 parent 0c26c51 commit ff57f10
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/odo/cli/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (o *InitOptions) Validate(ctx context.Context) error {
return err
}

if len(o.flags) == 0 && fcontext.GetOutput(ctx) {
if len(o.flags) == 0 && fcontext.IsJsonOutput(ctx) {
return errors.New("parameters are expected to select a devfile")
}
return nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/odo/commonflags/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ var (
runOnKey runOnKeyType
)

// WithOutput sets the value for the output flag (-o) in ctx
func WithOutput(ctx context.Context, val bool) context.Context {
// WithJsonOutput sets the value for the output flag (-o) in ctx
func WithJsonOutput(ctx context.Context, val bool) context.Context {
return context.WithValue(ctx, outputKey, val)
}

// GetOutput gets value of output flag (-o) in ctx
func GetOutput(ctx context.Context) bool {
// IsJsonOutput gets value of output flag (-o) in ctx
func IsJsonOutput(ctx context.Context) bool {
value := ctx.Value(outputKey)
if cast, ok := value.(bool); ok {
return cast
Expand Down
10 changes: 5 additions & 5 deletions pkg/odo/commonflags/context/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import (

func TestOutput(t *testing.T) {
ctx := context.TODO()
ctx = WithOutput(ctx, true)
res := GetOutput(ctx)
ctx = WithJsonOutput(ctx, true)
res := IsJsonOutput(ctx)
if res != true {
t.Errorf("GetOutput should return true but returns %v", res)
}

ctx = context.TODO()
res = GetOutput(ctx)
res = IsJsonOutput(ctx)
if res != false {
t.Errorf("GetOutput should return false but returns %v", res)
}

ctx = context.TODO()
ctx = WithOutput(ctx, false)
res = GetOutput(ctx)
ctx = WithJsonOutput(ctx, false)
res = IsJsonOutput(ctx)
if res != false {
t.Errorf("GetOutput should return false but returns %v", res)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/commonflags/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func CheckMachineReadableOutputCommand(cmd *cobra.Command) error {
return nil
}

// GetOutputValue returns true if -o flag is used and value is "json"
func GetOutputValue(cmd cmdline.Cmdline) bool {
// GetJsonOutputValue returns true if -o flag is used and value is "json"
func GetJsonOutputValue(cmd cmdline.Cmdline) bool {
return cmd.FlagValueIfSet(OutputFlagName) == "json"
}
4 changes: 2 additions & 2 deletions pkg/odo/commonflags/run_on.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func UseRunOnFlag(cmd *cobra.Command) {
// above traditional "persistentflags" usage that does not make it a pointer within the 'pflag'
// package
func AddRunOnFlag() {
flag.CommandLine.String(RunOnFlagName, "", "Specify target platform, supported platforms: cluster(default), podman")
flag.CommandLine.String(RunOnFlagName, "", `Specify target platform, supported platforms: "cluster" (default), "podman" (experimental)`)
_ = pflag.CommandLine.MarkHidden(RunOnFlagName)
}

Expand All @@ -45,7 +45,7 @@ func CheckRunOnCommand(cmd *cobra.Command) error {

// Check the valid output
if hasFlagChanged && runOnFlag.Value.String() != RunOnPodman && runOnFlag.Value.String() != RunOnCluster {
return fmt.Errorf("%s is not a valid target platform for --run-on, please select either cluster (default) or podman", runOnFlag.Value.String())
return fmt.Errorf(`%s is not a valid target platform for --run-on, please select either "cluster" (default) or "podman" (experimental)`, runOnFlag.Value.String())
}

// Check that if -o json has been passed, that the command actually USES json.. if not, error out.
Expand Down
2 changes: 1 addition & 1 deletion pkg/odo/commonflags/run_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestUseRunOnFlagWrongValue(t *testing.T) {
t.Errorf("Set error should be nil but is %v", err)
}
err = CheckRunOnCommand(cmd)
if err.Error() != "wrong-value is not a valid target platform for --run-on, please select either cluster (default) or podman" {
if err.Error() != `wrong-value is not a valid target platform for --run-on, please select either "cluster" (default) or "podman" (experimental)` {
t.Errorf("Check error is %v", err)
}
}
2 changes: 1 addition & 1 deletion pkg/odo/genericclioptions/runnable.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func GenericRun(o Runnable, cmd *cobra.Command, args []string) {
cmdLineObj := cmdline.NewCobra(cmd)

ctx := cmdLineObj.Context()
ctx = fcontext.WithOutput(ctx, commonflags.GetOutputValue(cmdLineObj))
ctx = fcontext.WithJsonOutput(ctx, commonflags.GetJsonOutputValue(cmdLineObj))
ctx = fcontext.WithRunOn(ctx, commonflags.GetRunOnValue(cmdLineObj))

// Run completion, validation and run.
Expand Down

0 comments on commit ff57f10

Please sign in to comment.