From a5fa70a07dc88abbb8df4b1d5ce9413bbf6b8f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 22 Oct 2021 14:15:09 +0200 Subject: [PATCH] :fire: obsolete `codespace/output` package --- go.mod | 1 - pkg/cmd/codespace/output/format_json.go | 55 ----------------- pkg/cmd/codespace/output/format_table.go | 31 ---------- pkg/cmd/codespace/output/format_tsv.go | 25 -------- pkg/cmd/codespace/output/logger.go | 78 ------------------------ 5 files changed, 190 deletions(-) delete mode 100644 pkg/cmd/codespace/output/format_json.go delete mode 100644 pkg/cmd/codespace/output/format_table.go delete mode 100644 pkg/cmd/codespace/output/format_tsv.go delete mode 100644 pkg/cmd/codespace/output/logger.go diff --git a/go.mod b/go.mod index c65e7341b..f28c0fe8a 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,6 @@ require ( github.com/muesli/reflow v0.2.1-0.20210502190812-c80126ec2ad5 github.com/muesli/termenv v0.9.0 github.com/muhammadmuzzammil1998/jsonc v0.0.0-20201229145248-615b0916ca38 - github.com/olekukonko/tablewriter v0.0.5 github.com/opentracing/opentracing-go v1.1.0 github.com/shurcooL/githubv4 v0.0.0-20200928013246-d292edc3691b github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f diff --git a/pkg/cmd/codespace/output/format_json.go b/pkg/cmd/codespace/output/format_json.go deleted file mode 100644 index 8488e8dfa..000000000 --- a/pkg/cmd/codespace/output/format_json.go +++ /dev/null @@ -1,55 +0,0 @@ -package output - -import ( - "encoding/json" - "io" - "strings" - "unicode" -) - -type jsonwriter struct { - w io.Writer - pretty bool - cols []string - data []interface{} -} - -func (j *jsonwriter) SetHeader(cols []string) { - j.cols = cols -} - -func (j *jsonwriter) Append(values []string) { - row := make(map[string]string) - for i, v := range values { - row[camelize(j.cols[i])] = v - } - j.data = append(j.data, row) -} - -func (j *jsonwriter) Render() { - enc := json.NewEncoder(j.w) - if j.pretty { - enc.SetIndent("", " ") - } - _ = enc.Encode(j.data) -} - -func camelize(s string) string { - var b strings.Builder - capitalizeNext := false - for i, r := range s { - if r == ' ' { - capitalizeNext = true - continue - } - if capitalizeNext { - b.WriteRune(unicode.ToUpper(r)) - capitalizeNext = false - } else if i == 0 { - b.WriteRune(unicode.ToLower(r)) - } else { - b.WriteRune(r) - } - } - return b.String() -} diff --git a/pkg/cmd/codespace/output/format_table.go b/pkg/cmd/codespace/output/format_table.go deleted file mode 100644 index e0345672d..000000000 --- a/pkg/cmd/codespace/output/format_table.go +++ /dev/null @@ -1,31 +0,0 @@ -package output - -import ( - "io" - "os" - - "github.com/olekukonko/tablewriter" - "golang.org/x/term" -) - -type Table interface { - SetHeader([]string) - Append([]string) - Render() -} - -func NewTable(w io.Writer, asJSON bool) Table { - isTTY := isTTY(w) - if asJSON { - return &jsonwriter{w: w, pretty: isTTY} - } - if isTTY { - return tablewriter.NewWriter(w) - } - return &tabwriter{w: w} -} - -func isTTY(w io.Writer) bool { - f, ok := w.(*os.File) - return ok && term.IsTerminal(int(f.Fd())) -} diff --git a/pkg/cmd/codespace/output/format_tsv.go b/pkg/cmd/codespace/output/format_tsv.go deleted file mode 100644 index 3f1d226ca..000000000 --- a/pkg/cmd/codespace/output/format_tsv.go +++ /dev/null @@ -1,25 +0,0 @@ -package output - -import ( - "fmt" - "io" -) - -type tabwriter struct { - w io.Writer -} - -func (j *tabwriter) SetHeader([]string) {} - -func (j *tabwriter) Append(values []string) { - var sep string - for i, v := range values { - if i == 1 { - sep = "\t" - } - fmt.Fprintf(j.w, "%s%s", sep, v) - } - fmt.Fprint(j.w, "\n") -} - -func (j *tabwriter) Render() {} diff --git a/pkg/cmd/codespace/output/logger.go b/pkg/cmd/codespace/output/logger.go deleted file mode 100644 index fdefcad0f..000000000 --- a/pkg/cmd/codespace/output/logger.go +++ /dev/null @@ -1,78 +0,0 @@ -package output - -import ( - "fmt" - "io" - "sync" -) - -// NewLogger returns a Logger that will write to the given stdout/stderr writers. -// Disable the Logger to prevent it from writing to stdout in a TTY environment. -func NewLogger(stdout, stderr io.Writer, disabled bool) *Logger { - enabled := !disabled - if isTTY(stdout) && !enabled { - enabled = false - } - return &Logger{ - out: stdout, - errout: stderr, - enabled: enabled, - } -} - -// Logger writes to the given stdout/stderr writers. -// If not enabled, Print functions will noop but Error functions will continue -// to write to the stderr writer. -type Logger struct { - mu sync.Mutex // guards the writers - out io.Writer - errout io.Writer - enabled bool -} - -// Print writes the arguments to the stdout writer. -func (l *Logger) Print(v ...interface{}) (int, error) { - if !l.enabled { - return 0, nil - } - - l.mu.Lock() - defer l.mu.Unlock() - return fmt.Fprint(l.out, v...) -} - -// Println writes the arguments to the stdout writer with a newline at the end. -func (l *Logger) Println(v ...interface{}) (int, error) { - if !l.enabled { - return 0, nil - } - - l.mu.Lock() - defer l.mu.Unlock() - return fmt.Fprintln(l.out, v...) -} - -// Printf writes the formatted arguments to the stdout writer. -func (l *Logger) Printf(f string, v ...interface{}) (int, error) { - if !l.enabled { - return 0, nil - } - - l.mu.Lock() - defer l.mu.Unlock() - return fmt.Fprintf(l.out, f, v...) -} - -// Errorf writes the formatted arguments to the stderr writer. -func (l *Logger) Errorf(f string, v ...interface{}) (int, error) { - l.mu.Lock() - defer l.mu.Unlock() - return fmt.Fprintf(l.errout, f, v...) -} - -// Errorln writes the arguments to the stderr writer with a newline at the end. -func (l *Logger) Errorln(v ...interface{}) (int, error) { - l.mu.Lock() - defer l.mu.Unlock() - return fmt.Fprintln(l.errout, v...) -}