Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit 078f627

Browse files
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

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/secrethub/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func main() {
11-
err := secrethub.NewApp().Version(secrethub.Version, secrethub.Commit).Run(os.Args[1:])
11+
err := secrethub.NewApp().Version(secrethub.Version, secrethub.Commit).Run()
1212
if err != nil {
1313
handleError(err)
1414
}

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ go 1.14
44

55
require (
66
bitbucket.org/zombiezen/cardcpx v0.0.0-20150417151802-902f68ff43ef
7-
cloud.google.com/go v0.57.0 // indirect
8-
github.com/alecthomas/kingpin v1.3.8-0.20200323085623-b6657d9477a6
97
github.com/atotto/clipboard v0.1.2
108
github.com/aws/aws-sdk-go v1.25.49
119
github.com/docker/go-units v0.3.3
@@ -15,12 +13,14 @@ require (
1513
github.com/mattn/go-isatty v0.0.7
1614
github.com/mitchellh/go-homedir v1.1.0
1715
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
18-
github.com/pkg/errors v0.9.1 // indirect
19-
github.com/secrethub/demo-app v0.1.0
20-
github.com/secrethub/secrethub-go v0.30.1-0.20201215150659-e5f45b9d8a0d
16+
github.com/secrethub/demo-app v0.5.1-0.20210105185858-ad55afc2cb87
17+
github.com/secrethub/secrethub-go v0.31.0
18+
github.com/spf13/cobra v1.0.0
19+
github.com/spf13/pflag v1.0.5
2120
github.com/zalando/go-keyring v0.0.0-20190208082241-fbe81aec3a07
2221
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
23-
golang.org/x/sys v0.0.0-20200501052902-10377860bb8e
22+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68
23+
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf
2424
golang.org/x/text v0.3.2
2525
google.golang.org/api v0.26.0
2626
gopkg.in/yaml.v2 v2.2.2

go.sum

Lines changed: 99 additions & 33 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)