diff --git a/cmd/list_task_names_verbose.go b/cmd/list_task_names_verbose.go new file mode 100644 index 0000000..cc7739f --- /dev/null +++ b/cmd/list_task_names_verbose.go @@ -0,0 +1,46 @@ +package cmd + +import ( + "strings" + "sort" + "fmt" + "bytes" +) + +// List full tasks names on one line +func ListTaskNamesVerbose(opts *mykeOpts, tasks []string) error { + w, err := loadWorkspace(opts.File) + if err != nil { + return err + } + + for _, p := range w.Projects { + tasks := []string{} + for t := range p.Tasks { + if !strings.HasPrefix(t, "_") { + tasks = append(tasks, t) + } + } + if len(tasks) > 0 { + sort.Strings(tasks) + var projectName bytes.Buffer + projectName.WriteString(p.Name) + projectName.WriteString("/") + projectTags := strings.Join(p.Tags, ",") + for _, sortedTask := range tasks { + var outputLine bytes.Buffer + outputLine.Write(projectName.Bytes()) + outputLine.WriteString(sortedTask) + outputLine.WriteString("\t") + outputLine.WriteString(projectTags) + outputLine.WriteString("\t") + task := p.Tasks[sortedTask] + outputLine.WriteString(task.Desc) + outputLine.WriteString("\t") + outputLine.WriteString(p.Src) + fmt.Fprintln(opts.Writer, outputLine.String()) + } + } + } + return nil +} diff --git a/cmd/root.go b/cmd/root.go index c09ae58..c952937 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,13 +12,14 @@ import ( ) type mykeOpts struct { - Verbose int `short:"v" long:"verbose" description:"verbosity level, <=0 nothing, =3 info, >=5 everything" default:"3"` - File string `short:"f" long:"file" description:"yml file to load" default:"myke.yml"` - DryRun bool `short:"n" long:"dry-run" description:"print tasks without running them"` - Version bool `long:"version" description:"print myke version"` - Template string `long:"template" description:"template file to render"` - License bool `long:"license" description:"show open source licenses"` - Writer io.Writer + Verbose int `short:"v" long:"verbose" description:"verbosity level, <=0 nothing, =3 info, >=5 everything" default:"3"` + File string `short:"f" long:"file" description:"yml file to load" default:"myke.yml"` + DryRun bool `short:"n" long:"dry-run" description:"print tasks without running them"` + Version bool `long:"version" description:"print myke version"` + Template string `long:"template" description:"template file to render"` + License bool `long:"license" description:"show open source licenses"` + TaskListVerbose bool `long:"tasks" description:"lists the full name of every known task and their associated tags, description and myke file path (tab separated)"` + Writer io.Writer } // Exec is CLI entrypoint @@ -73,6 +74,10 @@ func Action(opts *mykeOpts, tasks []string) error { return Run(opts, tasks) } + if opts.TaskListVerbose { + return ListTaskNamesVerbose(opts, tasks) + } + return List(opts) } diff --git a/dist/autocomplete/bash/myke_task_autocompletion.sh b/dist/autocomplete/bash/myke_task_autocompletion.sh new file mode 100644 index 0000000..fa8c19a --- /dev/null +++ b/dist/autocomplete/bash/myke_task_autocompletion.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +function _myke_task_complete() { + COMPREPLY=(); + local word="${COMP_WORDS[COMP_CWORD]}"; + COMPREPLY=($(compgen -W "$(myke --tasks | awk -v FS='\t' '{print $1}' | grep -e "^$word" -e "/$word")")); +} + +complete -F _myke_task_complete myke diff --git a/dist/autocomplete/fish/myke_task_autocompletion.fish b/dist/autocomplete/fish/myke_task_autocompletion.fish new file mode 100644 index 0000000..6ca8b75 --- /dev/null +++ b/dist/autocomplete/fish/myke_task_autocompletion.fish @@ -0,0 +1,2 @@ +#myke +complete -x -c myke -a "(myke --tasks )" \ No newline at end of file