Skip to content

CLI Commands use os.Exit/log.Fatalf instead of cobra's RunE, Args, and PreRun #281

@mynk8

Description

@mynk8

Reason/Context

There are several subtle input validation bugs in the arguments and the code is not fully utilizing the idiomatic features of cobra for handling errors and lifecycle.

Description

Here's a small list I can think of

  • No Args validators -- manual len(args) checks with cmd.HelpFunc() + os.Exit(1) instead of cobra's ExactArgs, MinimumNArgs
  • No PreRunE -- flag validation happens inside Run after network calls have started, instead of before
  • SilenceErrors not set -- cobra prints errors on top of the command's own error output

Some example validation loopholes

Implementation ideas

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions