mirror of
https://github.com/go-task/task.git
synced 2025-01-04 03:48:02 +02:00
parent
dfd890c8a6
commit
78f6cb08d8
@ -300,6 +300,9 @@ generate-files:
|
||||
You can use `--force` or `-f` if you want to force a task to run even when
|
||||
up-to-date.
|
||||
|
||||
Also, `task --status [tasks]...` will exit with non-zero exit code if any of
|
||||
the tasks is not up-to-date.
|
||||
|
||||
### Variables
|
||||
|
||||
When doing interpolation of variables, Task will look for the below.
|
||||
|
@ -50,6 +50,7 @@ func main() {
|
||||
versionFlag bool
|
||||
init bool
|
||||
list bool
|
||||
status bool
|
||||
force bool
|
||||
watch bool
|
||||
verbose bool
|
||||
@ -60,6 +61,7 @@ func main() {
|
||||
pflag.BoolVar(&versionFlag, "version", false, "show Task version")
|
||||
pflag.BoolVarP(&init, "init", "i", false, "creates a new Taskfile.yml in the current folder")
|
||||
pflag.BoolVarP(&list, "list", "l", false, "lists tasks with description of current Taskfile")
|
||||
pflag.BoolVar(&status, "status", false, "exits with non-zero exit code if any of the given tasks is not up-to-date")
|
||||
pflag.BoolVarP(&force, "force", "f", false, "forces execution even when the task is up-to-date")
|
||||
pflag.BoolVarP(&watch, "watch", "w", false, "enables watch of the given task")
|
||||
pflag.BoolVarP(&verbose, "verbose", "v", false, "enables verbose mode")
|
||||
@ -116,6 +118,13 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if status {
|
||||
if err = e.Status(calls...); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err := e.Run(calls...); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
18
status.go
18
status.go
@ -8,6 +8,24 @@ import (
|
||||
"github.com/go-task/task/internal/status"
|
||||
)
|
||||
|
||||
// Status returns an error if any the of given tasks is not up-to-date
|
||||
func (e *Executor) Status(calls ...Call) error {
|
||||
for _, call := range calls {
|
||||
t, ok := e.Tasks[call.Task]
|
||||
if !ok {
|
||||
return &taskNotFoundError{taskName: call.Task}
|
||||
}
|
||||
isUpToDate, err := t.isUpToDate(e.Context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !isUpToDate {
|
||||
return fmt.Errorf(`task: Task "%s" is not up-to-date`, t.Task)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Task) isUpToDate(ctx context.Context) (bool, error) {
|
||||
if len(t.Status) > 0 {
|
||||
return t.isUpToDateStatus(ctx)
|
||||
|
Loading…
Reference in New Issue
Block a user