diff --git a/cmd/oras/internal/option/common.go b/cmd/oras/internal/option/common.go index 0530ed056..7cb14a2c0 100644 --- a/cmd/oras/internal/option/common.go +++ b/cmd/oras/internal/option/common.go @@ -17,7 +17,6 @@ package option import ( "context" - "errors" "os" "github.com/sirupsen/logrus" @@ -37,7 +36,7 @@ type Common struct { // ApplyFlags applies flags to a command flag set. func (opts *Common) ApplyFlags(fs *pflag.FlagSet) { - fs.BoolVarP(&opts.Debug, "debug", "d", false, "debug mode") + fs.BoolVarP(&opts.Debug, "debug", "d", false, "output debug logs (implies --no-tty)") fs.BoolVarP(&opts.Verbose, "verbose", "v", false, "verbose output") fs.BoolVarP(&opts.noTTY, "no-tty", "", false, "[Preview] do not show progress output") } @@ -55,11 +54,12 @@ func (opts *Common) Parse() error { // parseTTY gets target options from user input. func (opts *Common) parseTTY(f *os.File) error { - if !opts.noTTY && term.IsTerminal(int(f.Fd())) { + if !opts.noTTY { if opts.Debug { - return errors.New("cannot use --debug, add --no-tty to suppress terminal output") + opts.noTTY = true + } else if term.IsTerminal(int(f.Fd())) { + opts.TTY = f } - opts.TTY = f } return nil } diff --git a/cmd/oras/internal/option/common_unix_test.go b/cmd/oras/internal/option/common_unix_test.go index 2d4388385..2ad72620f 100644 --- a/cmd/oras/internal/option/common_unix_test.go +++ b/cmd/oras/internal/option/common_unix_test.go @@ -38,7 +38,10 @@ func TestCommon_parseTTY(t *testing.T) { // --debug opts.Debug = true - if err := opts.parseTTY(device); err == nil { - t.Error("expected error when debug is set with TTY output") + if err := opts.parseTTY(device); err != nil { + t.Errorf("unexpected error with --debug: %v", err) + } + if !opts.noTTY { + t.Errorf("expected --no-tty to be true with --debug") } }