Skip to content

Commit

Permalink
feat: add version command, improve help
Browse files Browse the repository at this point in the history
Signed-off-by: Tobias Brumhard <code@brumhard.com>
  • Loading branch information
brumhard committed Jun 6, 2022
1 parent 1497ae7 commit db5e87a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cmd/earthly-secret-provider-vault/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/spf13/cobra"
)

const cli = "earthly-secret-provider-vault"

func main() {
cmd := buildRootCommand()
if err := cmd.Execute(); err != nil {
Expand All @@ -26,20 +28,20 @@ func buildRootCommand() *cobra.Command {
p := provider.New()

cmd := &cobra.Command{
Use: "earthly-secret-provider-vault",
Short: "earthly-secret-provider-vault is a secret provider for Earthly that connects to Vault",
Long: `earthly-secret-provider-vault is a secret provider for Earthly that connects to Hashicorp's Vault.
Use: cli,
Short: fmt.Sprintf("%s is a secret provider for Earthly that connects to Vault", cli),
Long: fmt.Sprintf(`%[1]s is a secret provider for Earthly that connects to Hashicorp's Vault.
For docs on how to configure this take a look here: https://docs.earthly.dev/docs/earthly-config#secret_provider-experimental.
Since the contract for secret providers is fairly simple you can test this provider by running:
$ earthly-secret-provider-vault <vault-path>
$ %[1]s <vault-path>
This print the secret on stdout.
Generally the CLI will look at ~/.vault-token and ~/.earthly/vault.yml for the configuration.
The token from ~/.vault-token will be used if it exists, otherwise the token from ~/.earthly/vault.yml will be used.
vault.yml should be used to set the Vault address and optionally a lookup secret can be added.
To set a config option in the vault.yml file, use the config subcommand.`,
To set a config option in the vault.yml file, use the config subcommand.`, cli),
// don't show errors and usage on errors in any RunE function.
SilenceErrors: true,
SilenceUsage: true,
Expand All @@ -48,5 +50,7 @@ To set a config option in the vault.yml file, use the config subcommand.`,
},
}

cmd.AddCommand(buildVersionCommand())

return cmd
}
23 changes: 23 additions & 0 deletions cmd/earthly-secret-provider-vault/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"fmt"
"runtime/debug"

"github.com/spf13/cobra"
)

func buildVersionCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: fmt.Sprintf("Print the version number of %s", cli),
Long: fmt.Sprintf("All software has versions. This is %s's.", cli),
Run: func(cmd *cobra.Command, args []string) {
if bi, ok := debug.ReadBuildInfo(); ok {
fmt.Printf("%+v\n", bi)
}
},
}

return cmd
}

0 comments on commit db5e87a

Please sign in to comment.