Skip to content

Commit ec809e7

Browse files
authored
Replace terminal UI with logger-based UI (#228)
* Replace terminal UI with logger-based UI This fixes #224. * Add reference to PR to changelog
1 parent a167443 commit ec809e7

File tree

4 files changed

+11
-152
lines changed

4 files changed

+11
-152
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ All notable changes to `src-cli` are documented in this file.
1717

1818
### Changed
1919

20+
- 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)
21+
2022
### Fixed
2123

2224
### Removed

cmd/src/actions_exec.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,14 @@ Format of the action JSON files:
253253
clearCache: *clearCacheFlag,
254254
cache: actionExecutionDiskCache{dir: *cacheDirFlag},
255255
}
256-
if !*verbose {
257-
opts.onUpdate = newTerminalUI(*keepLogsFlag)
258-
}
259256

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

268265
totalSteps := len(repos) * len(action.Steps)
269266
logger.Start(totalSteps)

cmd/src/actions_exec_logger.go

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,22 @@ func newActionLogger(verbose, keepLogs bool) *actionLogger {
6464
}
6565

6666
func (a *actionLogger) Start(totalSteps int) {
67-
if a.verbose {
68-
a.progress.SetTotalSteps(int64(totalSteps))
69-
fmt.Fprintln(os.Stderr)
70-
}
67+
a.progress.SetTotalSteps(int64(totalSteps))
7168
}
7269

7370
func (a *actionLogger) Infof(format string, args ...interface{}) {
74-
a.log("", grey, format, args...)
71+
if a.verbose {
72+
a.log("", grey, format, args...)
73+
}
7574
}
7675

7776
func (a *actionLogger) Warnf(format string, args ...interface{}) {
78-
a.log("", yellow, "WARNING: "+format, args...)
77+
if a.verbose {
78+
a.log("", yellow, "WARNING: "+format, args...)
79+
}
7980
}
8081

8182
func (a *actionLogger) ActionFailed(err error, patches []PatchInput) {
82-
if !a.verbose {
83-
return
84-
}
8583
a.out.Close()
8684
fmt.Fprintln(os.Stderr)
8785
if perr, ok := err.(parallel.Errors); ok {
@@ -106,9 +104,6 @@ func (a *actionLogger) ActionFailed(err error, patches []PatchInput) {
106104
}
107105

108106
func (a *actionLogger) ActionSuccess(patches []PatchInput) {
109-
if !a.verbose {
110-
return
111-
}
112107
a.out.Close()
113108
fmt.Fprintln(os.Stderr)
114109
format := "✔ Action produced %d patches."
@@ -151,18 +146,12 @@ func (a *actionLogger) RepoWriter(repoName string) (io.Writer, bool) {
151146
}
152147

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

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

176-
if !a.verbose {
177-
return w, w, ok
178-
}
179-
180165
stderrPrefix := fmt.Sprintf("%s -> [STDERR]: ", yellow.Sprint(repoName))
181166
stderr := textio.NewPrefixWriter(a.out, stderrPrefix)
182167

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

268-
// log logs only to stderr, it does not log to our repoWriters. When not in verbose mode, it's a noop.
253+
// log logs only to stderr, it does not log to our repoWriters.
269254
func (a *actionLogger) log(repoName string, c *color.Color, format string, args ...interface{}) {
270-
if !a.verbose {
271-
return
272-
}
273255
if len(repoName) > 0 {
274256
format = fmt.Sprintf("%s -> %s", c.Sprint(repoName), format)
275257
}

cmd/src/actions_terminal_ui.go

Lines changed: 0 additions & 122 deletions
This file was deleted.

0 commit comments

Comments
 (0)