mirror of
https://github.com/go-task/task.git
synced 2025-07-17 01:43:07 +02:00
feat: add --no-status
flag (#1368)
disables status check when running with `--list` `--json` options
This commit is contained in:
committed by
GitHub
parent
db2414402f
commit
8355f16809
@ -53,6 +53,7 @@ var flags struct {
|
||||
listJson bool
|
||||
taskSort string
|
||||
status bool
|
||||
noStatus bool
|
||||
insecure bool
|
||||
force bool
|
||||
forceAll bool
|
||||
@ -115,6 +116,7 @@ func run() error {
|
||||
pflag.BoolVarP(&flags.listJson, "json", "j", false, "Formats task list as JSON.")
|
||||
pflag.StringVar(&flags.taskSort, "sort", "", "Changes the order of the tasks when listed. [default|alphanumeric|none].")
|
||||
pflag.BoolVar(&flags.status, "status", false, "Exits with non-zero exit code if any of the given tasks is not up-to-date.")
|
||||
pflag.BoolVar(&flags.noStatus, "no-status", false, "Ignore status when listing tasks as JSON")
|
||||
pflag.BoolVar(&flags.insecure, "insecure", false, "Forces Task to download Taskfiles over insecure connections.")
|
||||
pflag.BoolVarP(&flags.watch, "watch", "w", false, "Enables watch of the given task.")
|
||||
pflag.BoolVarP(&flags.verbose, "verbose", "v", false, "Enables verbose mode.")
|
||||
@ -254,7 +256,7 @@ func run() error {
|
||||
TaskSorter: taskSorter,
|
||||
}
|
||||
|
||||
listOptions := task.NewListOptions(flags.list, flags.listAll, flags.listJson)
|
||||
listOptions := task.NewListOptions(flags.list, flags.listAll, flags.listJson, flags.noStatus)
|
||||
if err := listOptions.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
84
help.go
84
help.go
@ -24,14 +24,16 @@ type ListOptions struct {
|
||||
ListOnlyTasksWithDescriptions bool
|
||||
ListAllTasks bool
|
||||
FormatTaskListAsJSON bool
|
||||
NoStatus bool
|
||||
}
|
||||
|
||||
// NewListOptions creates a new ListOptions instance
|
||||
func NewListOptions(list, listAll, listAsJson bool) ListOptions {
|
||||
func NewListOptions(list, listAll, listAsJson, noStatus bool) ListOptions {
|
||||
return ListOptions{
|
||||
ListOnlyTasksWithDescriptions: list,
|
||||
ListAllTasks: listAll,
|
||||
FormatTaskListAsJSON: listAsJson,
|
||||
NoStatus: noStatus,
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,6 +50,9 @@ func (o ListOptions) Validate() error {
|
||||
if o.FormatTaskListAsJSON && !o.ShouldListTasks() {
|
||||
return fmt.Errorf("task: --json only applies to --list or --list-all")
|
||||
}
|
||||
if o.NoStatus && !o.FormatTaskListAsJSON {
|
||||
return fmt.Errorf("task: --no-status only applies to --json with --list or --list-all")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -73,7 +78,7 @@ func (e *Executor) ListTasks(o ListOptions) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
if o.FormatTaskListAsJSON {
|
||||
output, err := e.ToEditorOutput(tasks)
|
||||
output, err := e.ToEditorOutput(tasks, o.NoStatus)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -154,7 +159,7 @@ func (e *Executor) ListTaskNames(allTasks bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Executor) ToEditorOutput(tasks []*taskfile.Task) (*editors.Taskfile, error) {
|
||||
func (e *Executor) ToEditorOutput(tasks []*taskfile.Task, noStatus bool) (*editors.Taskfile, error) {
|
||||
o := &editors.Taskfile{
|
||||
Tasks: make([]editors.Task, len(tasks)),
|
||||
Location: e.Taskfile.Location,
|
||||
@ -163,34 +168,51 @@ func (e *Executor) ToEditorOutput(tasks []*taskfile.Task) (*editors.Taskfile, er
|
||||
for i := range tasks {
|
||||
task := tasks[i]
|
||||
j := i
|
||||
g.Go(func() error {
|
||||
// Get the fingerprinting method to use
|
||||
method := e.Taskfile.Method
|
||||
if task.Method != "" {
|
||||
method = task.Method
|
||||
}
|
||||
upToDate, err := fingerprint.IsTaskUpToDate(context.Background(), task,
|
||||
fingerprint.WithMethod(method),
|
||||
fingerprint.WithTempDir(e.TempDir),
|
||||
fingerprint.WithDry(e.Dry),
|
||||
fingerprint.WithLogger(e.Logger),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.Tasks[j] = editors.Task{
|
||||
Name: task.Name(),
|
||||
Desc: task.Desc,
|
||||
Summary: task.Summary,
|
||||
UpToDate: upToDate,
|
||||
Location: &editors.Location{
|
||||
Line: task.Location.Line,
|
||||
Column: task.Location.Column,
|
||||
Taskfile: task.Location.Taskfile,
|
||||
},
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if noStatus {
|
||||
g.Go(func() error {
|
||||
o.Tasks[j] = editors.Task{
|
||||
Name: task.Name(),
|
||||
Desc: task.Desc,
|
||||
Summary: task.Summary,
|
||||
UpToDate: false,
|
||||
Location: &editors.Location{
|
||||
Line: task.Location.Line,
|
||||
Column: task.Location.Column,
|
||||
Taskfile: task.Location.Taskfile,
|
||||
},
|
||||
}
|
||||
return nil
|
||||
})
|
||||
} else {
|
||||
g.Go(func() error {
|
||||
// Get the fingerprinting method to use
|
||||
method := e.Taskfile.Method
|
||||
if task.Method != "" {
|
||||
method = task.Method
|
||||
}
|
||||
upToDate, err := fingerprint.IsTaskUpToDate(context.Background(), task,
|
||||
fingerprint.WithMethod(method),
|
||||
fingerprint.WithTempDir(e.TempDir),
|
||||
fingerprint.WithDry(e.Dry),
|
||||
fingerprint.WithLogger(e.Logger),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.Tasks[j] = editors.Task{
|
||||
Name: task.Name(),
|
||||
Desc: task.Desc,
|
||||
Summary: task.Summary,
|
||||
UpToDate: upToDate,
|
||||
Location: &editors.Location{
|
||||
Line: task.Location.Line,
|
||||
Column: task.Location.Column,
|
||||
Taskfile: task.Location.Taskfile,
|
||||
},
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
}
|
||||
return o, g.Wait()
|
||||
}
|
||||
|
Reference in New Issue
Block a user