package cli import ( "fmt" "io" "runtime" "github.com/spf13/cobra" "sneak.berlin/go/vaultik/internal/globals" ) // NewVersionCommand creates the version command func NewVersionCommand() *cobra.Command { cmd := &cobra.Command{ Use: "version", Short: "Print version information", Long: `Print version, git commit, and build information for vaultik.`, Args: cobra.NoArgs, Run: func(cmd *cobra.Command, _ []string) { writeVersion(cmd.OutOrStdout()) }, } return cmd } // writeVersion prints the version report. It takes a writer rather than // using os.Stdout directly so the output can be asserted on in tests. func writeVersion(w io.Writer) { _, _ = fmt.Fprintf(w, "vaultik %s\n", globals.Version) _, _ = fmt.Fprintf(w, " commit: %s\n", globals.Commit) _, _ = fmt.Fprintf(w, " build date: %s\n", globals.CommitDate) _, _ = fmt.Fprintf(w, " go: %s\n", runtime.Version()) _, _ = fmt.Fprintf(w, " os/arch: %s/%s\n", runtime.GOOS, runtime.GOARCH) _, _ = fmt.Fprintf(w, " author: %s\n", globals.Author) _, _ = fmt.Fprintf(w, " homepage: %s\n", globals.Homepage) _, _ = fmt.Fprintf(w, " license: %s\n", globals.License) if globals.IsDevVersion(globals.Version) { _, _ = fmt.Fprintln(w) _, _ = fmt.Fprintln(w, "This is a development build: it was not built from a tagged") _, _ = fmt.Fprintln(w, "commit, so it carries no release version. Released binaries") _, _ = fmt.Fprintf(w, "are published at %s\n", globals.ReleasesURL) _, _ = fmt.Fprintln(w, "and report their tag on the first line above.") } }