From 5cd87e0ffe927c7e3b80f62df23ff136a94c014e Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Feb 2026 12:37:09 +0000 Subject: [PATCH] feat(cli): add --quiet flag and ProgressFromCmd helper Wire the Progress interface into the CLI by adding a --quiet/-q global flag and a ProgressFromCmd helper that returns QuietProgress (stderr) when --quiet is set, or DefaultProgress (TTY-aware) otherwise. Co-Authored-By: Claude Opus 4.6 --- cmd/context.go | 17 +++++++++++++++++ cmd/context_test.go | 28 ++++++++++++++++++++++++++++ cmd/root.go | 1 + 3 files changed, 46 insertions(+) create mode 100644 cmd/context.go create mode 100644 cmd/context_test.go diff --git a/cmd/context.go b/cmd/context.go new file mode 100644 index 0000000..7fd164c --- /dev/null +++ b/cmd/context.go @@ -0,0 +1,17 @@ +package cmd + +import ( + "os" + + "github.com/Snider/Borg/pkg/ui" + "github.com/spf13/cobra" +) + +// ProgressFromCmd returns a Progress based on --quiet flag and TTY detection. +func ProgressFromCmd(cmd *cobra.Command) ui.Progress { + quiet, _ := cmd.Flags().GetBool("quiet") + if quiet { + return ui.NewQuietProgress(os.Stderr) + } + return ui.DefaultProgress() +} diff --git a/cmd/context_test.go b/cmd/context_test.go new file mode 100644 index 0000000..0e54903 --- /dev/null +++ b/cmd/context_test.go @@ -0,0 +1,28 @@ +package cmd + +import ( + "testing" + + "github.com/spf13/cobra" +) + +func TestProgressFromCmd_Good(t *testing.T) { + cmd := &cobra.Command{} + cmd.PersistentFlags().BoolP("quiet", "q", false, "") + + p := ProgressFromCmd(cmd) + if p == nil { + t.Fatal("expected non-nil Progress") + } +} + +func TestProgressFromCmd_Quiet_Good(t *testing.T) { + cmd := &cobra.Command{} + cmd.PersistentFlags().BoolP("quiet", "q", true, "") + _ = cmd.PersistentFlags().Set("quiet", "true") + + p := ProgressFromCmd(cmd) + if p == nil { + t.Fatal("expected non-nil Progress") + } +} diff --git a/cmd/root.go b/cmd/root.go index 9cadb27..dd41d6f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -16,6 +16,7 @@ packaging their contents into a single file, and managing the data within.`, } rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Enable verbose logging") + rootCmd.PersistentFlags().BoolP("quiet", "q", false, "Suppress non-error output") return rootCmd }