Skip to content

Commit

Permalink
fix: Report any unknown options found on the command line.
Browse files Browse the repository at this point in the history
Card ID: CCT-524

The rhc subcommands, connect, disconnect and status ignore any
unknown options given. This PR will fix this by returning an
error when any unknown options are found.
  • Loading branch information
jvlcek committed Oct 22, 2024
1 parent 22aa0f1 commit 8689826
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func beforeConnectAction(ctx *cli.Context) error {
}
}

return nil
return checkForUnknownArgs(ctx)
}

// connectAction tries to register system against Red Hat Subscription Management,
Expand Down Expand Up @@ -487,7 +487,12 @@ func (connectResult ConnectResult) Error() string {

// beforeDisconnectAction ensures the used has supplied a correct `--format` flag
func beforeDisconnectAction(ctx *cli.Context) error {
return setupFormatOption(ctx)
err := setupFormatOption(ctx)
if err != nil {
return err
}

return checkForUnknownArgs(ctx)
}

// interactivePrintf is method for printing human-readable output. It suppresses output, when
Expand Down Expand Up @@ -648,7 +653,12 @@ func printJSONStatus(systemStatus *SystemStatus) error {

// beforeStatusAction ensures the user has supplied a correct `--format` flag.
func beforeStatusAction(ctx *cli.Context) error {
return setupFormatOption(ctx)
err := setupFormatOption(ctx)
if err != nil {
return err
}

return checkForUnknownArgs(ctx)
}

// statusAction tries to print status of system. It means that it gives
Expand Down
9 changes: 9 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,12 @@ func getLocale() string {
locale := os.Getenv("LANG")
return locale
}

// checkForUnknownArgs returns an error if any unknown arguments are present.
func checkForUnknownArgs(ctx *cli.Context) error {
if ctx.Args().Len() != 0 {
return fmt.Errorf("error: unknown option(s): %s",
strings.Join(ctx.Args().Slice(), " "))
}
return nil
}

0 comments on commit 8689826

Please sign in to comment.