From 819a14f40da0932941766a8f7e7a979c863fbdc2 Mon Sep 17 00:00:00 2001 From: Philipp Rosenkranz Date: Thu, 21 Jun 2018 16:34:36 +0200 Subject: [PATCH 1/2] add basic task autocompletion --- cmd/list_full_task_names.go | 39 +++++++++++++++++++ cmd/root.go | 17 +++++--- .../bash/myke_task_autocompletion.sh | 9 +++++ .../fish/myke_task_autocompletion.fish | 2 + 4 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 cmd/list_full_task_names.go create mode 100644 dist/autocomplete/bash/myke_task_autocompletion.sh create mode 100644 dist/autocomplete/fish/myke_task_autocompletion.fish diff --git a/cmd/list_full_task_names.go b/cmd/list_full_task_names.go new file mode 100644 index 0000000..b9ad57d --- /dev/null +++ b/cmd/list_full_task_names.go @@ -0,0 +1,39 @@ +package cmd + +import ( + "strings" + "sort" + "fmt" + "bytes" +) + +// List full tasks names on one line +func ListFullTaskNames(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("/") + for _, sortedTask := range tasks { + var fullTaskName bytes.Buffer + fullTaskName.Write(projectName.Bytes()) + fullTaskName.WriteString(sortedTask) + fullTaskName.WriteString(" ") + fmt.Fprintln(opts.Writer, fullTaskName.String()) + } + } + } + return nil +} diff --git a/cmd/root.go b/cmd/root.go index c09ae58..9e85ff7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,12 +12,13 @@ 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"` + 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"` + ListFullTaskNames bool `long:"tasks" description:"lists the full name of every known tasks"` Writer io.Writer } @@ -73,6 +74,10 @@ func Action(opts *mykeOpts, tasks []string) error { return Run(opts, tasks) } + if opts.ListFullTaskNames { + return ListFullTaskNames(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..8c6446b --- /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 | 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..d5921a3 --- /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 From 7f244dbc29860d655fefa7c5b30111e38be04002 Mon Sep 17 00:00:00 2001 From: Philipp Rosenkranz Date: Fri, 29 Jun 2018 18:40:41 +0200 Subject: [PATCH 2/2] add project tags, task description and myke file location to each full task name --- ...sk_names.go => list_task_names_verbose.go} | 19 ++++++++++++------ cmd/root.go | 20 +++++++++---------- .../bash/myke_task_autocompletion.sh | 2 +- .../fish/myke_task_autocompletion.fish | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-) rename cmd/{list_full_task_names.go => list_task_names_verbose.go} (50%) diff --git a/cmd/list_full_task_names.go b/cmd/list_task_names_verbose.go similarity index 50% rename from cmd/list_full_task_names.go rename to cmd/list_task_names_verbose.go index b9ad57d..cc7739f 100644 --- a/cmd/list_full_task_names.go +++ b/cmd/list_task_names_verbose.go @@ -8,7 +8,7 @@ import ( ) // List full tasks names on one line -func ListFullTaskNames(opts *mykeOpts, tasks []string) error { +func ListTaskNamesVerbose(opts *mykeOpts, tasks []string) error { w, err := loadWorkspace(opts.File) if err != nil { return err @@ -26,12 +26,19 @@ func ListFullTaskNames(opts *mykeOpts, tasks []string) error { var projectName bytes.Buffer projectName.WriteString(p.Name) projectName.WriteString("/") + projectTags := strings.Join(p.Tags, ",") for _, sortedTask := range tasks { - var fullTaskName bytes.Buffer - fullTaskName.Write(projectName.Bytes()) - fullTaskName.WriteString(sortedTask) - fullTaskName.WriteString(" ") - fmt.Fprintln(opts.Writer, fullTaskName.String()) + 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()) } } } diff --git a/cmd/root.go b/cmd/root.go index 9e85ff7..c952937 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,14 +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"` - ListFullTaskNames bool `long:"tasks" description:"lists the full name of every known tasks"` - 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 @@ -74,8 +74,8 @@ func Action(opts *mykeOpts, tasks []string) error { return Run(opts, tasks) } - if opts.ListFullTaskNames { - return ListFullTaskNames(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 index 8c6446b..fa8c19a 100644 --- a/dist/autocomplete/bash/myke_task_autocompletion.sh +++ b/dist/autocomplete/bash/myke_task_autocompletion.sh @@ -3,7 +3,7 @@ function _myke_task_complete() { COMPREPLY=(); local word="${COMP_WORDS[COMP_CWORD]}"; - COMPREPLY=($(compgen -W "$(myke --tasks | grep -e "^$word" -e "/$word")")); + 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 index d5921a3..6ca8b75 100644 --- a/dist/autocomplete/fish/myke_task_autocompletion.fish +++ b/dist/autocomplete/fish/myke_task_autocompletion.fish @@ -1,2 +1,2 @@ #myke -complete -x -c myke -a '(myke --tasks)' \ No newline at end of file +complete -x -c myke -a "(myke --tasks )" \ No newline at end of file