check / check (pull_request) Successful in 1m45s
version, info, remote info, config, and database delete wrote plain text straight to stdout, so they were unstyled and ignored --quiet. Output now falls in two buckets, both governed by internal/ui. Status lines and confirmations (config init, config set, database delete) go through the ui message methods: styled, and --quiet silences them. The data a command exists to produce is written plain, since a marker would corrupt a table or a parsed document: the version, info, and remote info reports, the snapshot list table, config get values, and the --json documents. --quiet silences the human reports and tables but never the config get value or the --json documents, which a script depends on. The database delete confirmation prompt is always shown; it is an interactive exchange the operator must see. The pure-cli commands reach internal/ui through a small commandUI helper that builds a ui.Writer on the command's stdout in quiet mode when --quiet is set. NewForTesting now supplies a UI writer so the quiet gate is never nil. The README output-style section states the resulting rule. Model: opus-4-8
60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
|
|
"github.com/spf13/cobra"
|
|
"sneak.berlin/go/vaultik/internal/globals"
|
|
"sneak.berlin/go/vaultik/internal/ui"
|
|
)
|
|
|
|
// 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(commandUI(cmd))
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
// writeVersion prints the version report through the UI writer. The
|
|
// report is the output this command exists to produce, so it is written
|
|
// plain (markers would corrupt the aligned report) via the writer's
|
|
// underlying stdout; --quiet silences it like any other non-error
|
|
// output.
|
|
func writeVersion(out *ui.Writer) {
|
|
if out.Quiet() {
|
|
return
|
|
}
|
|
|
|
w := out.Out()
|
|
|
|
_, _ = 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.")
|
|
}
|
|
}
|