Skip to content

Commit

Permalink
Replace terminal UI with logger-based UI (#228)
Browse files Browse the repository at this point in the history
* Replace terminal UI with logger-based UI

This fixes #224.

* Add reference to PR to changelog
  • Loading branch information
mrnugget authored Jun 22, 2020
1 parent c88f1c9 commit 5095bdb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 152 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ All notable changes to `src-cli` are documented in this file.

### Changed

- The terminal UI has been replaced by the logger-based UI that was previously only visible in verbose-mode (`-v`). [#228](https://github.com/sourcegraph/src-cli/pull/228)

### Fixed

### Removed
Expand Down
5 changes: 1 addition & 4 deletions cmd/src/actions_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,14 @@ Format of the action JSON files:
clearCache: *clearCacheFlag,
cache: actionExecutionDiskCache{dir: *cacheDirFlag},
}
if !*verbose {
opts.onUpdate = newTerminalUI(*keepLogsFlag)
}

// Query repos over which to run action
logger.Infof("Querying %s for repositories matching '%s'...\n", cfg.Endpoint, action.ScopeQuery)
repos, err := actionRepos(ctx, action.ScopeQuery, *includeUnsupportedFlag, logger)
if err != nil {
return err
}
logger.Infof("Use 'src actions scope-query' for help with scoping.\n")
logger.Infof("Use 'src actions scope-query' for help with scoping.\n\n")

totalSteps := len(repos) * len(action.Steps)
logger.Start(totalSteps)
Expand Down
34 changes: 8 additions & 26 deletions cmd/src/actions_exec_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,22 @@ func newActionLogger(verbose, keepLogs bool) *actionLogger {
}

func (a *actionLogger) Start(totalSteps int) {
if a.verbose {
a.progress.SetTotalSteps(int64(totalSteps))
fmt.Fprintln(os.Stderr)
}
a.progress.SetTotalSteps(int64(totalSteps))
}

func (a *actionLogger) Infof(format string, args ...interface{}) {
a.log("", grey, format, args...)
if a.verbose {
a.log("", grey, format, args...)
}
}

func (a *actionLogger) Warnf(format string, args ...interface{}) {
a.log("", yellow, "WARNING: "+format, args...)
if a.verbose {
a.log("", yellow, "WARNING: "+format, args...)
}
}

func (a *actionLogger) ActionFailed(err error, patches []PatchInput) {
if !a.verbose {
return
}
a.out.Close()
fmt.Fprintln(os.Stderr)
if perr, ok := err.(parallel.Errors); ok {
Expand All @@ -106,9 +104,6 @@ func (a *actionLogger) ActionFailed(err error, patches []PatchInput) {
}

func (a *actionLogger) ActionSuccess(patches []PatchInput) {
if !a.verbose {
return
}
a.out.Close()
fmt.Fprintln(os.Stderr)
format := "✔ Action produced %d patches."
Expand Down Expand Up @@ -151,18 +146,12 @@ func (a *actionLogger) RepoWriter(repoName string) (io.Writer, bool) {
}

func (a *actionLogger) InfoPipe(prefix string) io.Writer {
if !a.verbose {
return ioutil.Discard
}
stdoutPrefix := fmt.Sprintf("%s -> [STDOUT]: ", yellow.Sprint(prefix))
stderr := textio.NewPrefixWriter(os.Stderr, stdoutPrefix)
return io.Writer(stderr)
}

func (a *actionLogger) ErrorPipe(prefix string) io.Writer {
if !a.verbose {
return ioutil.Discard
}
stderrPrefix := fmt.Sprintf("%s -> [STDERR]: ", yellow.Sprint(prefix))
stderr := textio.NewPrefixWriter(os.Stderr, stderrPrefix)
return io.Writer(stderr)
Expand All @@ -173,10 +162,6 @@ func (a *actionLogger) RepoStdoutStderr(repoName string) (io.Writer, io.Writer,
defer a.mu.Unlock()
w, ok := a.logWriters[repoName]

if !a.verbose {
return w, w, ok
}

stderrPrefix := fmt.Sprintf("%s -> [STDERR]: ", yellow.Sprint(repoName))
stderr := textio.NewPrefixWriter(a.out, stderrPrefix)

Expand Down Expand Up @@ -265,11 +250,8 @@ func (a *actionLogger) write(repoName string, c *color.Color, format string, arg
a.log(repoName, c, format, args...)
}

// log logs only to stderr, it does not log to our repoWriters. When not in verbose mode, it's a noop.
// log logs only to stderr, it does not log to our repoWriters.
func (a *actionLogger) log(repoName string, c *color.Color, format string, args ...interface{}) {
if !a.verbose {
return
}
if len(repoName) > 0 {
format = fmt.Sprintf("%s -> %s", c.Sprint(repoName), format)
}
Expand Down
122 changes: 0 additions & 122 deletions cmd/src/actions_terminal_ui.go

This file was deleted.

0 comments on commit 5095bdb

Please sign in to comment.