Skip to content

Commit

Permalink
add task-level warning prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
parkerduckworth committed Jul 20, 2020
1 parent a6f7984 commit a0abd48
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type Executor struct {

Dir string
Entrypoint string
Warning string
Force bool
Watch bool
Verbose bool
Expand Down Expand Up @@ -257,6 +256,13 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {
return &MaximumTaskCallExceededError{task: call.Task}
}

if t.Warning != "" {
response := promptWithWarning(t.Warning)
if !isConfirmed(response) {
return errors.New("cancelled at warning")
}
}

if err := e.runDeps(ctx, t); err != nil {
return err
}
Expand Down Expand Up @@ -348,13 +354,10 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi
return nil
case cmd.Cmd != "":
if cmd.Warning != "" {
fmt.Printf("%s (y/N): ", cmd.Warning)

var response string
fmt.Scanln(&response)

response := promptWithWarning(cmd.Warning)
if !isConfirmed(response) {
return errors.New("cancelled at warning")
// Continue to next cmd
return nil
}
}

Expand Down Expand Up @@ -413,6 +416,15 @@ func getEnviron(t *taskfile.Task) []string {
return environ
}

func promptWithWarning(warning string) string {
fmt.Printf("%s (y/N): ", warning)

var response string
fmt.Scanln(&response)

return response
}

func isConfirmed(response string) bool {
affirmativeResponses := []string{"y", "yes"}

Expand Down

0 comments on commit a0abd48

Please sign in to comment.