Skip to content

Commit 8cfac5a

Browse files
authored
refactor: remove newlines from formatter print functions (go-task#1137)
1 parent 1e8fc50 commit 8cfac5a

File tree

11 files changed

+58
-58
lines changed

11 files changed

+58
-58
lines changed

cmd/task/task.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func run() error {
255255
}
256256

257257
if err := e.Run(ctx, calls...); err != nil {
258-
e.Logger.Errf(logger.Red, "%v", err)
258+
e.Logger.Errf(logger.Red, "%v\n", err)
259259

260260
if exitCode {
261261
if err, ok := err.(*errors.TaskRunError); ok {

help.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,24 @@ func (e *Executor) ListTasks(o ListOptions) (bool, error) {
8888
}
8989
if len(tasks) == 0 {
9090
if o.ListOnlyTasksWithDescriptions {
91-
e.Logger.Outf(logger.Yellow, "task: No tasks with description available. Try --list-all to list all tasks")
91+
e.Logger.Outf(logger.Yellow, "task: No tasks with description available. Try --list-all to list all tasks\n")
9292
} else if o.ListAllTasks {
93-
e.Logger.Outf(logger.Yellow, "task: No tasks available")
93+
e.Logger.Outf(logger.Yellow, "task: No tasks available\n")
9494
}
9595
return false, nil
9696
}
97-
e.Logger.Outf(logger.Default, "task: Available tasks for this project:")
97+
e.Logger.Outf(logger.Default, "task: Available tasks for this project:\n")
9898

9999
// Format in tab-separated columns with a tab stop of 8.
100100
w := tabwriter.NewWriter(e.Stdout, 0, 8, 6, ' ', 0)
101101
for _, task := range tasks {
102-
e.Logger.FOutf(w, logger.Yellow, "* ")
103-
e.Logger.FOutf(w, logger.Green, task.Task)
104-
e.Logger.FOutf(w, logger.Default, ": \t%s", task.Desc)
102+
e.Logger.Outf(logger.Yellow, "* ")
103+
e.Logger.Outf(logger.Green, task.Task)
104+
e.Logger.Outf(logger.Default, ": \t%s", task.Desc)
105105
if len(task.Aliases) > 0 {
106-
e.Logger.FOutf(w, logger.Cyan, "\t(aliases: %s)", strings.Join(task.Aliases, ", "))
106+
e.Logger.Outf(logger.Cyan, "\t(aliases: %s)", strings.Join(task.Aliases, ", "))
107107
}
108-
_, _ = fmt.Fprint(w, "\n")
108+
e.Logger.Outf(logger.Default, "\n")
109109
}
110110
if err := w.Flush(); err != nil {
111111
return false, err

internal/compiler/v2/compiler_v2.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (c *CompilerV2) HandleDynamicVar(v taskfile.Var, _ string) (string, error)
117117
result := strings.TrimSuffix(stdout.String(), "\n")
118118

119119
c.dynamicCache[v.Sh] = result
120-
c.Logger.VerboseErrf(logger.Magenta, `task: dynamic variable: '%s' result: '%s'`, v.Sh, result)
120+
c.Logger.VerboseErrf(logger.Magenta, "task: dynamic variable: %q result: %q\n", v.Sh, result)
121121

122122
return result, nil
123123
}

internal/compiler/v3/compiler_v3.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (c *CompilerV3) HandleDynamicVar(v taskfile.Var, dir string) (string, error
161161
result = strings.TrimSuffix(result, "\n")
162162

163163
c.dynamicCache[v.Sh] = result
164-
c.Logger.VerboseErrf(logger.Magenta, `task: dynamic variable: '%s' result: '%s'`, v.Sh, result)
164+
c.Logger.VerboseErrf(logger.Magenta, "task: dynamic variable: %q result: %q\n", v.Sh, result)
165165

166166
return result, nil
167167
}

internal/fingerprint/status.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ func (checker *StatusChecker) IsUpToDate(ctx context.Context, t *taskfile.Task)
2727
Env: env.Get(t),
2828
})
2929
if err != nil {
30-
checker.logger.VerboseOutf(logger.Yellow, "task: status command %s exited non-zero: %s", s, err)
30+
checker.logger.VerboseOutf(logger.Yellow, "task: status command %s exited non-zero: %s\n", s, err)
3131
return false, nil
3232
}
33-
checker.logger.VerboseOutf(logger.Yellow, "task: status command %s exited zero", s)
33+
checker.logger.VerboseOutf(logger.Yellow, "task: status command %s exited zero\n", s)
3434
}
3535
return true, nil
3636
}

internal/logger/logger.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type Logger struct {
6464

6565
// Outf prints stuff to STDOUT.
6666
func (l *Logger) Outf(color Color, s string, args ...any) {
67-
l.FOutf(l.Stdout, color, s+"\n", args...)
67+
l.FOutf(l.Stdout, color, s, args...)
6868
}
6969

7070
// FOutf prints stuff to the given writer.
@@ -95,7 +95,7 @@ func (l *Logger) Errf(color Color, s string, args ...any) {
9595
color = Default
9696
}
9797
print := color()
98-
print(l.Stderr, s+"\n", args...)
98+
print(l.Stderr, s, args...)
9999
}
100100

101101
// VerboseErrf prints stuff to STDERR if verbose mode is enabled.

internal/summary/summary.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func PrintSpaceBetweenSummaries(l *logger.Logger, i int) {
2020
return
2121
}
2222

23-
l.Outf(logger.Default, "")
24-
l.Outf(logger.Default, "")
23+
l.Outf(logger.Default, "\n")
24+
l.Outf(logger.Default, "\n")
2525
}
2626

2727
func PrintTask(l *logger.Logger, t *taskfile.Task) {
@@ -51,26 +51,26 @@ func printTaskSummary(l *logger.Logger, t *taskfile.Task) {
5151
for i, line := range lines {
5252
notLastLine := i+1 < len(lines)
5353
if notLastLine || line != "" {
54-
l.Outf(logger.Default, line)
54+
l.Outf(logger.Default, "%s\n", line)
5555
}
5656
}
5757
}
5858

5959
func printTaskName(l *logger.Logger, t *taskfile.Task) {
60-
l.FOutf(l.Stdout, logger.Default, "task: ")
61-
l.FOutf(l.Stdout, logger.Green, "%s\n", t.Name())
62-
l.Outf(logger.Default, "")
60+
l.Outf(logger.Default, "task: ")
61+
l.Outf(logger.Green, "%s\n", t.Name())
62+
l.Outf(logger.Default, "\n")
6363
}
6464

6565
func printTaskAliases(l *logger.Logger, t *taskfile.Task) {
6666
if len(t.Aliases) == 0 {
6767
return
6868
}
69-
l.Outf(logger.Default, "")
70-
l.Outf(logger.Default, "aliases:")
69+
l.Outf(logger.Default, "\n")
70+
l.Outf(logger.Default, "aliases:\n")
7171
for _, alias := range t.Aliases {
72-
l.FOutf(l.Stdout, logger.Default, " - ")
73-
l.Outf(logger.Cyan, alias)
72+
l.Outf(logger.Default, " - ")
73+
l.Outf(logger.Cyan, "%s\n", alias)
7474
}
7575
}
7676

@@ -79,23 +79,23 @@ func hasDescription(t *taskfile.Task) bool {
7979
}
8080

8181
func printTaskDescription(l *logger.Logger, t *taskfile.Task) {
82-
l.Outf(logger.Default, t.Desc)
82+
l.Outf(logger.Default, "%s\n", t.Desc)
8383
}
8484

8585
func printNoDescriptionOrSummary(l *logger.Logger) {
86-
l.Outf(logger.Default, "(task does not have description or summary)")
86+
l.Outf(logger.Default, "(task does not have description or summary)\n")
8787
}
8888

8989
func printTaskDependencies(l *logger.Logger, t *taskfile.Task) {
9090
if len(t.Deps) == 0 {
9191
return
9292
}
9393

94-
l.Outf(logger.Default, "")
95-
l.Outf(logger.Default, "dependencies:")
94+
l.Outf(logger.Default, "\n")
95+
l.Outf(logger.Default, "dependencies:\n")
9696

9797
for _, d := range t.Deps {
98-
l.Outf(logger.Default, " - %s", d.Task)
98+
l.Outf(logger.Default, " - %s\n", d.Task)
9999
}
100100
}
101101

@@ -104,15 +104,15 @@ func printTaskCommands(l *logger.Logger, t *taskfile.Task) {
104104
return
105105
}
106106

107-
l.Outf(logger.Default, "")
108-
l.Outf(logger.Default, "commands:")
107+
l.Outf(logger.Default, "\n")
108+
l.Outf(logger.Default, "commands:\n")
109109
for _, c := range t.Cmds {
110110
isCommand := c.Cmd != ""
111-
l.FOutf(l.Stdout, logger.Default, " - ")
111+
l.Outf(logger.Default, " - ")
112112
if isCommand {
113-
l.FOutf(l.Stdout, logger.Yellow, "%s\n", c.Cmd)
113+
l.Outf(logger.Yellow, "%s\n", c.Cmd)
114114
} else {
115-
l.FOutf(l.Stdout, logger.Green, "Task: %s\n", c.Task)
115+
l.Outf(logger.Green, "Task: %s\n", c.Task)
116116
}
117117
}
118118
}

precondition.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (e *Executor) areTaskPreconditionsMet(ctx context.Context, t *taskfile.Task
2121
Env: env.Get(t),
2222
})
2323
if err != nil {
24-
e.Logger.Errf(logger.Magenta, "task: %s", p.Msg)
24+
e.Logger.Errf(logger.Magenta, "task: %s\n", p.Msg)
2525
return false, ErrPreconditionFailed
2626
}
2727
}

signals.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ func (e *Executor) InterceptInterruptSignals() {
2020
sig := <-ch
2121

2222
if i < 3 {
23-
e.Logger.Outf(logger.Yellow, `task: Signal received: "%s"`, sig)
23+
e.Logger.Outf(logger.Yellow, "task: Signal received: %q\n", sig)
2424
continue
2525
}
2626

27-
e.Logger.Errf(logger.Red, `task: Signal received for the third time: "%s". Forcing shutdown`, sig)
27+
e.Logger.Errf(logger.Red, "task: Signal received for the third time: %q. Forcing shutdown\n", sig)
2828
os.Exit(1)
2929
}
3030
}()

task.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {
141141

142142
return e.startExecution(ctx, t, func(ctx context.Context) error {
143143
if !shouldRunOnCurrentPlatform(t.Platforms) {
144-
e.Logger.VerboseOutf(logger.Yellow, `task: "%s" not for current platform - ignored`, call.Task)
144+
e.Logger.VerboseOutf(logger.Yellow, `task: %q not for current platform - ignored\n`, call.Task)
145145
return nil
146146
}
147147

148-
e.Logger.VerboseErrf(logger.Magenta, `task: "%s" started`, call.Task)
148+
e.Logger.VerboseErrf(logger.Magenta, "task: %q started\n", call.Task)
149149
if err := e.runDeps(ctx, t); err != nil {
150150
return err
151151
}
@@ -178,14 +178,14 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {
178178

179179
if upToDate && preCondMet {
180180
if e.Verbose || (!t.Silent && !e.Taskfile.Silent && !e.Silent) {
181-
e.Logger.Errf(logger.Magenta, `task: Task "%s" is up to date`, t.Name())
181+
e.Logger.Errf(logger.Magenta, "task: Task %q is up to date\n", t.Name())
182182
}
183183
return nil
184184
}
185185
}
186186

187187
if err := e.mkdir(t); err != nil {
188-
e.Logger.Errf(logger.Red, "task: cannot make directory %q: %v", t.Dir, err)
188+
e.Logger.Errf(logger.Red, "task: cannot make directory %q: %v\n", t.Dir, err)
189189
}
190190

191191
for i := range t.Cmds {
@@ -196,18 +196,18 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {
196196

197197
if err := e.runCommand(ctx, t, call, i); err != nil {
198198
if err2 := e.statusOnError(t); err2 != nil {
199-
e.Logger.VerboseErrf(logger.Yellow, "task: error cleaning status on error: %v", err2)
199+
e.Logger.VerboseErrf(logger.Yellow, "task: error cleaning status on error: %v\n", err2)
200200
}
201201

202202
if execext.IsExitError(err) && t.IgnoreError {
203-
e.Logger.VerboseErrf(logger.Yellow, "task: task error ignored: %v", err)
203+
e.Logger.VerboseErrf(logger.Yellow, "task: task error ignored: %v\n", err)
204204
continue
205205
}
206206

207207
return &errors.TaskRunError{TaskName: t.Task, Err: err}
208208
}
209209
}
210-
e.Logger.VerboseErrf(logger.Magenta, `task: "%s" finished`, call.Task)
210+
e.Logger.VerboseErrf(logger.Magenta, "task: %q finished\n", call.Task)
211211
return nil
212212
})
213213
}
@@ -255,7 +255,7 @@ func (e *Executor) runDeferred(t *taskfile.Task, call taskfile.Call, i int) {
255255
defer cancel()
256256

257257
if err := e.runCommand(ctx, t, call, i); err != nil {
258-
e.Logger.VerboseErrf(logger.Yellow, `task: ignored error in deferred cmd: %s`, err.Error())
258+
e.Logger.VerboseErrf(logger.Yellow, "task: ignored error in deferred cmd: %s\n", err.Error())
259259
}
260260
}
261261

@@ -274,12 +274,12 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi
274274
return nil
275275
case cmd.Cmd != "":
276276
if !shouldRunOnCurrentPlatform(cmd.Platforms) {
277-
e.Logger.VerboseOutf(logger.Yellow, `task: [%s] %s not for current platform - ignored`, t.Name(), cmd.Cmd)
277+
e.Logger.VerboseOutf(logger.Yellow, "task: [%s] %s not for current platform - ignored\n", t.Name(), cmd.Cmd)
278278
return nil
279279
}
280280

281281
if e.Verbose || (!cmd.Silent && !t.Silent && !e.Taskfile.Silent && !e.Silent) {
282-
e.Logger.Errf(logger.Green, "task: [%s] %s", t.Name(), cmd.Cmd)
282+
e.Logger.Errf(logger.Green, "task: [%s] %s\n", t.Name(), cmd.Cmd)
283283
}
284284

285285
if e.Dry {
@@ -308,10 +308,10 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi
308308
Stderr: stdErr,
309309
})
310310
if closeErr := close(err); closeErr != nil {
311-
e.Logger.Errf(logger.Red, "task: unable to close writer: %v", closeErr)
311+
e.Logger.Errf(logger.Red, "task: unable to close writer: %v\n", closeErr)
312312
}
313313
if execext.IsExitError(err) && cmd.IgnoreError {
314-
e.Logger.VerboseErrf(logger.Yellow, "task: [%s] command error ignored: %v", t.Name(), err)
314+
e.Logger.VerboseErrf(logger.Yellow, "task: [%s] command error ignored: %v\n", t.Name(), err)
315315
return nil
316316
}
317317
return err
@@ -334,7 +334,7 @@ func (e *Executor) startExecution(ctx context.Context, t *taskfile.Task, execute
334334

335335
if otherExecutionCtx, ok := e.executionHashes[h]; ok {
336336
e.executionHashesMutex.Unlock()
337-
e.Logger.VerboseErrf(logger.Magenta, "task: skipping execution of task: %s", h)
337+
e.Logger.VerboseErrf(logger.Magenta, "task: skipping execution of task: %s\n", h)
338338

339339
// Release our execution slot to avoid blocking other tasks while we wait
340340
reacquire := e.releaseConcurrencyLimit()

watch.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error {
3434
c := c
3535
go func() {
3636
if err := e.RunTask(ctx, c); err != nil && !isContextError(err) {
37-
e.Logger.Errf(logger.Red, "%v", err)
37+
e.Logger.Errf(logger.Red, "%v\n", err)
3838
}
3939
}()
4040
}
@@ -49,7 +49,7 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error {
4949
watchInterval = defaultWatchInterval
5050
}
5151

52-
e.Logger.VerboseOutf(logger.Green, "task: Watching for changes every %v", watchInterval)
52+
e.Logger.VerboseOutf(logger.Green, "task: Watching for changes every %v\n", watchInterval)
5353

5454
w := watcher.New()
5555
defer w.Close()
@@ -61,7 +61,7 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error {
6161
for {
6262
select {
6363
case event := <-w.Event:
64-
e.Logger.VerboseErrf(logger.Magenta, "task: received watch event: %v", event)
64+
e.Logger.VerboseErrf(logger.Magenta, "task: received watch event: %v\n", event)
6565

6666
cancel()
6767
ctx, cancel = context.WithCancel(context.Background())
@@ -72,15 +72,15 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error {
7272
c := c
7373
go func() {
7474
if err := e.RunTask(ctx, c); err != nil && !isContextError(err) {
75-
e.Logger.Errf(logger.Red, "%v", err)
75+
e.Logger.Errf(logger.Red, "%v\n", err)
7676
}
7777
}()
7878
}
7979
case err := <-w.Error:
8080
switch err {
8181
case watcher.ErrWatchedFileDeleted:
8282
default:
83-
e.Logger.Errf(logger.Red, "%v", err)
83+
e.Logger.Errf(logger.Red, "%v\n", err)
8484
}
8585
case <-w.Closed:
8686
cancel()
@@ -93,7 +93,7 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error {
9393
// re-register every 5 seconds because we can have new files, but this process is expensive to run
9494
for {
9595
if err := e.registerWatchedFiles(w, calls...); err != nil {
96-
e.Logger.Errf(logger.Red, "%v", err)
96+
e.Logger.Errf(logger.Red, "%v\n", err)
9797
}
9898
time.Sleep(watchInterval)
9999
}
@@ -161,7 +161,7 @@ func (e *Executor) registerWatchedFiles(w *watcher.Watcher, calls ...taskfile.Ca
161161
if err := w.Add(absFile); err != nil {
162162
return err
163163
}
164-
e.Logger.VerboseOutf(logger.Green, "task: watching new file: %v", absFile)
164+
e.Logger.VerboseOutf(logger.Green, "task: watching new file: %v\n", absFile)
165165
}
166166
}
167167
return nil

0 commit comments

Comments
 (0)