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