Skip to content

Commit

Permalink
feat: make --debug imply --no-tty (#1162)
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah authored Nov 3, 2023
1 parent 5d95881 commit b911ad6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 5 additions & 5 deletions cmd/oras/internal/option/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package option

import (
"context"
"errors"
"os"

"github.com/sirupsen/logrus"
Expand All @@ -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")
}
Expand All @@ -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
}
7 changes: 5 additions & 2 deletions cmd/oras/internal/option/common_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit b911ad6

Please sign in to comment.