Skip to content

Better subcommand processing #206

@rdowavic

Description

@rdowavic

We've just added support for gitbackup init and gitbackup validate (currently still in #203 ) and the processing of subcommands is a bit messy without some kind of framework. Especially as the tool expands it would help to have better scaffolding for this.

Right now we manually check os.Args[1] in a switch statement which has some downsides:

  • no automatic help text that lists available subcommands
  • no shell completion
  • flag validation/subcommand wiring is messy

It looks like the most popular options are cobra (~43k stars), urfave/cli (~24k stars), kong (~3k stars), and ff/ffcli (~1.4k stars).

  1. cobra
    The strong points to this one are that it has auto-generated help, shell completion, and man pages. We'd have to change the project structure a bit (adding a cmd/ directory) and there would be a bit of refactoring involved with processing flags.

  2. urfave/cli
    This seems like it would be a lower migration effort since it doesn't involve a project restructure. also has shell completion. looks also like processing the flags is a 1:1 conversion (StringVar -> StringFlag)

  3. kong
    Seems like the migration would be pretty low effort because the package isn't opinionated at all about project structure -- but it's a small project with a small community which could be riskier. Also it looks like refactoring the config file override logic (combining config file with overriding flags) is a little more involved, need to use a "kong Resolver"

  4. ff/ffcli
    Same as kong, a small community which seems less desirable. it seems like a really low effort migration but we just won't get shell completion, or help text formatting..

Overall I would go with either cobra or urfave/cli, maybe favouring urfave/cli a little bit. Let me know your thoughts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions