This repository was archived by the owner on Feb 16, 2023. It is now read-only.
Commit 078f627
authored
Switch the CLI library from KingPin to Cobra (#333)
The change to Cobra is made for two main reasons:
- KingPin is no longer maintained
- Cobra enables argument autocompletion in addition to command and flag completion
Also, Cobra comes with some other enhancements that make the CLI construction simpler and more consistent.
The following list of key changes have been made in the codebase:
1. Visible to the user:
- custom template that is similar to cobra's; the following additions on top of the default cobra template were made:
- group commands with subcommands under `Management Commands` section
- add `Arguments` section for explaining the arguments
- divide the help text from command's/flag's name in a separate column for readibility
- add `-h` shorthand for help text
- automatically shows help text if the user does not provide a subcommand where one is required, e.g. `secrethub repo`
- when the user does not provide the required number of arguments, the CLI will provide an error message similar to docker's
- the versioning system: while in the previous version commands like `secrethub read --version` would have been valid, in this version, the `--version` flag can only be called on the root command, i.e. `secrethub --version`.
2. Visible to the developer
- refactor `env.go` file's functions into `argument.go`, `app.go`, and `flag.go` for better maintainability
- cobra's cutom template can be adjusted in `cobra_template.go`, located now in `internals/cli`
- flag registration has a similar syntax to cobra's
- argument registration is made using `BindArguments` and `BindArgumentsArr` (for commands that accept multiple arguments of the same type, e.g. `secrethub mkdir`), since KingPin includes argumnet registration, while cobra does not; this function enables the developer to save the argument's value to a variable that can be later used when executing the command
- the bug involving the `NoEnvVar` function not removing the environment variable corresponding to the flag it was called on has been solved
- `CommandClause` has two more new fields: `Args` (for linking variables to argument values), and `flags` (for enabling the link between the flag and its euqivalent environment variable)1 parent 34f62cf commit 078f627
105 files changed
Lines changed: 2042 additions & 1181 deletions
File tree
- cmd/secrethub
- internals
- cli
- filemode
- ui
- demo
- secrethub
- command
- scripts
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | 7 | | |
10 | 8 | | |
11 | 9 | | |
| |||
15 | 13 | | |
16 | 14 | | |
17 | 15 | | |
18 | | - | |
19 | | - | |
20 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
21 | 20 | | |
22 | 21 | | |
23 | | - | |
| 22 | + | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
Large diffs are not rendered by default.
0 commit comments