mirror of
https://github.com/go-task/task.git
synced 2025-02-09 13:47:06 +02:00
print logs to stderr instead of stdout
also, don't print up-to-date status when the --silent flag was given closes #68
This commit is contained in:
parent
14676dc3f8
commit
abb19dfbf8
2
help.go
2
help.go
@ -12,7 +12,7 @@ func (e *Executor) PrintTasksHelp() {
|
|||||||
if len(tasks) == 0 {
|
if len(tasks) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
e.println("Available tasks for this project:")
|
e.outf("Available tasks for this project:")
|
||||||
|
|
||||||
// Format in tab-separated columns with a tab stop of 8.
|
// Format in tab-separated columns with a tab stop of 8.
|
||||||
w := tabwriter.NewWriter(e.Stdout, 0, 8, 0, '\t', 0)
|
w := tabwriter.NewWriter(e.Stdout, 0, 8, 0, '\t', 0)
|
||||||
|
26
log.go
26
log.go
@ -4,22 +4,28 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (e *Executor) println(args ...interface{}) {
|
func (e *Executor) outf(s string, args ...interface{}) {
|
||||||
fmt.Fprintln(e.Stdout, args...)
|
if len(args) == 0 {
|
||||||
|
s, args = "%s", []interface{}{s}
|
||||||
|
}
|
||||||
|
fmt.Fprintf(e.Stdout, s+"\n", args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Executor) printfln(format string, args ...interface{}) {
|
func (e *Executor) verboseOutf(s string, args ...interface{}) {
|
||||||
fmt.Fprintf(e.Stdout, format+"\n", args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Executor) verbosePrintln(args ...interface{}) {
|
|
||||||
if e.Verbose {
|
if e.Verbose {
|
||||||
e.println(args...)
|
e.outf(s, args...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Executor) verbosePrintfln(format string, args ...interface{}) {
|
func (e *Executor) errf(s string, args ...interface{}) {
|
||||||
|
if len(args) == 0 {
|
||||||
|
s, args = "%s", []interface{}{s}
|
||||||
|
}
|
||||||
|
fmt.Fprintf(e.Stderr, s+"\n", args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Executor) verboseErrf(s string, args ...interface{}) {
|
||||||
if e.Verbose {
|
if e.Verbose {
|
||||||
e.printfln(format, args...)
|
e.errf(s, args...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
task.go
8
task.go
@ -126,7 +126,9 @@ func (e *Executor) RunTask(ctx context.Context, call Call) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if upToDate {
|
if upToDate {
|
||||||
e.printfln(`task: Task "%s" is up to date`, t.Task)
|
if !e.Silent {
|
||||||
|
e.errf(`task: Task "%s" is up to date`, t.Task)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,7 +136,7 @@ func (e *Executor) RunTask(ctx context.Context, call Call) error {
|
|||||||
for i := range t.Cmds {
|
for i := range t.Cmds {
|
||||||
if err := e.runCommand(ctx, t, call, i); err != nil {
|
if err := e.runCommand(ctx, t, call, i); err != nil {
|
||||||
if err2 := t.statusOnError(); err2 != nil {
|
if err2 := t.statusOnError(); err2 != nil {
|
||||||
e.verbosePrintfln("task: error cleaning status on error: %v", err2)
|
e.verboseErrf("task: error cleaning status on error: %v", err2)
|
||||||
}
|
}
|
||||||
return &taskRunError{t.Task, err}
|
return &taskRunError{t.Task, err}
|
||||||
}
|
}
|
||||||
@ -164,7 +166,7 @@ func (e *Executor) runCommand(ctx context.Context, t *Task, call Call, i int) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
if e.Verbose || (!cmd.Silent && !t.Silent && !e.Silent) {
|
if e.Verbose || (!cmd.Silent && !t.Silent && !e.Silent) {
|
||||||
e.println(cmd.Cmd)
|
e.errf(cmd.Cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
return execext.RunCommand(&execext.RunCommandOptions{
|
return execext.RunCommand(&execext.RunCommandOptions{
|
||||||
|
@ -189,7 +189,7 @@ func (e *Executor) handleShVar(v Var) (string, error) {
|
|||||||
result := strings.TrimSuffix(stdout.String(), "\n")
|
result := strings.TrimSuffix(stdout.String(), "\n")
|
||||||
|
|
||||||
e.dynamicCache[v.Sh] = result
|
e.dynamicCache[v.Sh] = result
|
||||||
e.verbosePrintfln(`task: dynamic variable: '%s' result: '%s'`, v.Sh, result)
|
e.verboseErrf(`task: dynamic variable: '%s' result: '%s'`, v.Sh, result)
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
12
watch.go
12
watch.go
@ -20,14 +20,14 @@ func (e *Executor) watchTasks(calls ...Call) error {
|
|||||||
for i, c := range calls {
|
for i, c := range calls {
|
||||||
tasks[i] = c.Task
|
tasks[i] = c.Task
|
||||||
}
|
}
|
||||||
e.printfln("task: Started watching for tasks: %s", strings.Join(tasks, ", "))
|
e.errf("task: Started watching for tasks: %s", strings.Join(tasks, ", "))
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
for _, c := range calls {
|
for _, c := range calls {
|
||||||
c := c
|
c := c
|
||||||
go func() {
|
go func() {
|
||||||
if err := e.RunTask(ctx, c); err != nil && !isContextError(err) {
|
if err := e.RunTask(ctx, c); err != nil && !isContextError(err) {
|
||||||
e.println(err)
|
e.errf("%v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ func (e *Executor) watchTasks(calls ...Call) error {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case event := <-w.Event:
|
case event := <-w.Event:
|
||||||
e.verbosePrintfln("task: received watch event: %v", event)
|
e.verboseErrf("task: received watch event: %v", event)
|
||||||
|
|
||||||
cancel()
|
cancel()
|
||||||
ctx, cancel = context.WithCancel(context.Background())
|
ctx, cancel = context.WithCancel(context.Background())
|
||||||
@ -51,7 +51,7 @@ func (e *Executor) watchTasks(calls ...Call) error {
|
|||||||
c := c
|
c := c
|
||||||
go func() {
|
go func() {
|
||||||
if err := e.RunTask(ctx, c); err != nil && !isContextError(err) {
|
if err := e.RunTask(ctx, c); err != nil && !isContextError(err) {
|
||||||
e.println(err)
|
e.errf("%v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ func (e *Executor) watchTasks(calls ...Call) error {
|
|||||||
w.TriggerEvent(watcher.Remove, nil)
|
w.TriggerEvent(watcher.Remove, nil)
|
||||||
}()
|
}()
|
||||||
default:
|
default:
|
||||||
e.println(err)
|
e.errf("%v", err)
|
||||||
}
|
}
|
||||||
case <-w.Closed:
|
case <-w.Closed:
|
||||||
return
|
return
|
||||||
@ -74,7 +74,7 @@ func (e *Executor) watchTasks(calls ...Call) error {
|
|||||||
// re-register each second because we can have new files
|
// re-register each second because we can have new files
|
||||||
for {
|
for {
|
||||||
if err := e.registerWatchedFiles(w, tasks); err != nil {
|
if err := e.registerWatchedFiles(w, tasks); err != nil {
|
||||||
e.println(err)
|
e.errf("%v", err)
|
||||||
}
|
}
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user