mirror of
https://github.com/go-task/task.git
synced 2025-01-04 03:48:02 +02:00
Add -f flag to force execution even when task is up-to-date
This commit is contained in:
parent
e95e2e8e8a
commit
131499b66d
@ -24,6 +24,7 @@ hello:
|
||||
'''
|
||||
`)
|
||||
}
|
||||
flag.BoolVar(&task.Force, "f", false, "forces execution even when the task is up-to-date")
|
||||
flag.Parse()
|
||||
task.Run()
|
||||
}
|
||||
|
8
task.go
8
task.go
@ -3,6 +3,7 @@ package task
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@ -21,6 +22,9 @@ var (
|
||||
// ShPath constains the Bash path if found
|
||||
ShPath string
|
||||
|
||||
// Force (-f flag) forces a task to run even when it's up-to-date
|
||||
Force bool
|
||||
|
||||
// Tasks constains the tasks parsed from Taskfile
|
||||
Tasks = make(map[string]*Task)
|
||||
)
|
||||
@ -64,7 +68,7 @@ func (err *taskRunError) Error() string {
|
||||
func Run() {
|
||||
log.SetFlags(0)
|
||||
|
||||
args := os.Args[1:]
|
||||
args := flag.Args()
|
||||
if len(args) == 0 {
|
||||
log.Fatal("No argument given")
|
||||
}
|
||||
@ -89,7 +93,7 @@ func RunTask(name string) error {
|
||||
return &taskNotFoundError{name}
|
||||
}
|
||||
|
||||
if isTaskUpToDate(t) {
|
||||
if !Force && isTaskUpToDate(t) {
|
||||
log.Printf(`Task "%s" is up to date`, name)
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user