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 <noreply@anthropic.com>
This commit is contained in:
parent
73b438f894
commit
5cd87e0ffe
3 changed files with 46 additions and 0 deletions
17
cmd/context.go
Normal file
17
cmd/context.go
Normal file
|
|
@ -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()
|
||||
}
|
||||
28
cmd/context_test.go
Normal file
28
cmd/context_test.go
Normal file
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue