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>
28 lines
541 B
Go
28 lines
541 B
Go
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")
|
|
}
|
|
}
|