Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add basic task autocompletion #107

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions cmd/list_task_names_verbose.go
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 12 additions & 7 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
9 changes: 9 additions & 0 deletions dist/autocomplete/bash/myke_task_autocompletion.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions dist/autocomplete/fish/myke_task_autocompletion.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#myke
complete -x -c myke -a "(myke --tasks )"