Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make --debug imply --no-tty #1162

Merged
merged 5 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)")
qweeah marked this conversation as resolved.
Show resolved Hide resolved
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")
}
}
Loading