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
|
listJson bool
|
||||||
taskSort string
|
taskSort string
|
||||||
status bool
|
status bool
|
||||||
|
noStatus bool
|
||||||
insecure bool
|
insecure bool
|
||||||
force bool
|
force bool
|
||||||
forceAll bool
|
forceAll bool
|
||||||
@ -115,6 +116,7 @@ func run() error {
|
|||||||
pflag.BoolVarP(&flags.listJson, "json", "j", false, "Formats task list as JSON.")
|
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.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.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.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.watch, "watch", "w", false, "Enables watch of the given task.")
|
||||||
pflag.BoolVarP(&flags.verbose, "verbose", "v", false, "Enables verbose mode.")
|
pflag.BoolVarP(&flags.verbose, "verbose", "v", false, "Enables verbose mode.")
|
||||||
@ -254,7 +256,7 @@ func run() error {
|
|||||||
TaskSorter: taskSorter,
|
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 {
|
if err := listOptions.Validate(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
84
help.go
84
help.go
@ -24,14 +24,16 @@ type ListOptions struct {
|
|||||||
ListOnlyTasksWithDescriptions bool
|
ListOnlyTasksWithDescriptions bool
|
||||||
ListAllTasks bool
|
ListAllTasks bool
|
||||||
FormatTaskListAsJSON bool
|
FormatTaskListAsJSON bool
|
||||||
|
NoStatus bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewListOptions creates a new ListOptions instance
|
// NewListOptions creates a new ListOptions instance
|
||||||
func NewListOptions(list, listAll, listAsJson bool) ListOptions {
|
func NewListOptions(list, listAll, listAsJson, noStatus bool) ListOptions {
|
||||||
return ListOptions{
|
return ListOptions{
|
||||||
ListOnlyTasksWithDescriptions: list,
|
ListOnlyTasksWithDescriptions: list,
|
||||||
ListAllTasks: listAll,
|
ListAllTasks: listAll,
|
||||||
FormatTaskListAsJSON: listAsJson,
|
FormatTaskListAsJSON: listAsJson,
|
||||||
|
NoStatus: noStatus,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +50,9 @@ func (o ListOptions) Validate() error {
|
|||||||
if o.FormatTaskListAsJSON && !o.ShouldListTasks() {
|
if o.FormatTaskListAsJSON && !o.ShouldListTasks() {
|
||||||
return fmt.Errorf("task: --json only applies to --list or --list-all")
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +78,7 @@ func (e *Executor) ListTasks(o ListOptions) (bool, error) {
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if o.FormatTaskListAsJSON {
|
if o.FormatTaskListAsJSON {
|
||||||
output, err := e.ToEditorOutput(tasks)
|
output, err := e.ToEditorOutput(tasks, o.NoStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
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{
|
o := &editors.Taskfile{
|
||||||
Tasks: make([]editors.Task, len(tasks)),
|
Tasks: make([]editors.Task, len(tasks)),
|
||||||
Location: e.Taskfile.Location,
|
Location: e.Taskfile.Location,
|
||||||
@ -163,34 +168,51 @@ func (e *Executor) ToEditorOutput(tasks []*taskfile.Task) (*editors.Taskfile, er
|
|||||||
for i := range tasks {
|
for i := range tasks {
|
||||||
task := tasks[i]
|
task := tasks[i]
|
||||||
j := i
|
j := i
|
||||||
g.Go(func() error {
|
if noStatus {
|
||||||
// Get the fingerprinting method to use
|
g.Go(func() error {
|
||||||
method := e.Taskfile.Method
|
o.Tasks[j] = editors.Task{
|
||||||
if task.Method != "" {
|
Name: task.Name(),
|
||||||
method = task.Method
|
Desc: task.Desc,
|
||||||
}
|
Summary: task.Summary,
|
||||||
upToDate, err := fingerprint.IsTaskUpToDate(context.Background(), task,
|
UpToDate: false,
|
||||||
fingerprint.WithMethod(method),
|
Location: &editors.Location{
|
||||||
fingerprint.WithTempDir(e.TempDir),
|
Line: task.Location.Line,
|
||||||
fingerprint.WithDry(e.Dry),
|
Column: task.Location.Column,
|
||||||
fingerprint.WithLogger(e.Logger),
|
Taskfile: task.Location.Taskfile,
|
||||||
)
|
},
|
||||||
if err != nil {
|
}
|
||||||
return err
|
return nil
|
||||||
}
|
})
|
||||||
o.Tasks[j] = editors.Task{
|
} else {
|
||||||
Name: task.Name(),
|
g.Go(func() error {
|
||||||
Desc: task.Desc,
|
// Get the fingerprinting method to use
|
||||||
Summary: task.Summary,
|
method := e.Taskfile.Method
|
||||||
UpToDate: upToDate,
|
if task.Method != "" {
|
||||||
Location: &editors.Location{
|
method = task.Method
|
||||||
Line: task.Location.Line,
|
}
|
||||||
Column: task.Location.Column,
|
upToDate, err := fingerprint.IsTaskUpToDate(context.Background(), task,
|
||||||
Taskfile: task.Location.Taskfile,
|
fingerprint.WithMethod(method),
|
||||||
},
|
fingerprint.WithTempDir(e.TempDir),
|
||||||
}
|
fingerprint.WithDry(e.Dry),
|
||||||
return nil
|
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()
|
return o, g.Wait()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user