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

added task #1239

Merged
merged 1 commit into from
Jul 27, 2022
Merged
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
55 changes: 55 additions & 0 deletions completers/task_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/task"
"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "task",
Short: "A task runner / simpler Make alternative written in Go",
Long: "https://taskfile.dev/",
Run: func(cmd *cobra.Command, args []string) {},
}

func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()

rootCmd.Flags().BoolP("color", "c", false, "colored output. Enabled by default. Set flag to false or use NO_COLOR=1 to disable (default true)")
rootCmd.Flags().StringP("concurrency", "C", "", "limit number tasks to run concurrently")
rootCmd.Flags().StringP("dir", "d", "", "sets directory of execution")
rootCmd.Flags().BoolP("dry", "n", false, "compiles and prints tasks in the order that they would be run, without executing them")
rootCmd.Flags().BoolP("exit-code", "x", false, "pass-through the exit code of the task command")
rootCmd.Flags().BoolP("force", "f", false, "forces execution even when the task is up-to-date")
rootCmd.Flags().BoolP("help", "h", false, "shows Task usage")
rootCmd.Flags().BoolP("init", "i", false, "creates a new Taskfile.yaml in the current folder")
rootCmd.Flags().BoolP("list", "l", false, "lists tasks with description of current Taskfile")
rootCmd.Flags().BoolP("list-all", "a", false, "lists tasks with or without a description")
rootCmd.Flags().StringP("output", "o", "", "sets output style: [interleaved|group|prefixed]")
rootCmd.Flags().String("output-group-begin", "", "message template to print before a task's grouped output")
rootCmd.Flags().String("output-group-end", "", "message template to print after a task's grouped output")
rootCmd.Flags().BoolP("parallel", "p", false, "executes tasks provided on command line in parallel")
rootCmd.Flags().BoolP("silent", "s", false, "disables echoing")
rootCmd.Flags().Bool("status", false, "exits with non-zero exit code if any of the given tasks is not up-to-date")
rootCmd.Flags().Bool("summary", false, "show summary about a task")
rootCmd.Flags().StringP("taskfile", "t", "", "choose which Taskfile to run. Defaults to \"Taskfile.yml\"")
rootCmd.Flags().BoolP("verbose", "v", false, "enables verbose mode")
rootCmd.Flags().Bool("version", false, "show Task version")
rootCmd.Flags().BoolP("watch", "w", false, "enables watch of the given task")

carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"dir": carapace.ActionDirectories(),
"output": carapace.ActionValues("interleaved", "group", "prefixed"),
"taskfile": carapace.ActionFiles(".yml", ".yaml"),
})

carapace.Gen(rootCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return task.ActionTasks(rootCmd.Flag("taskfile").Value.String()).Chdir(rootCmd.Flag("dir").Value.String()).Invoke(c).Filter(c.Args).ToA()
}),
)
}
7 changes: 7 additions & 0 deletions completers/task_completer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/rsteube/carapace-bin/completers/task_completer/cmd"

func main() {
cmd.Execute()
}
32 changes: 32 additions & 0 deletions pkg/actions/tools/task/task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package task

import (
"regexp"
"strings"

"github.com/rsteube/carapace"
)

// ActionTasks completes tasks
// default
// build (build the project)
func ActionTasks(file string) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
args := []string{"--list-all"}
if file != "" {
args = append(args, "--taskfile", file)
}
return carapace.ActionExecCommand("task", args...)(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
r := regexp.MustCompile(`^[*] (?P<name>[^ ]+):( \t*(?P<description>.*))?$`)

vals := make([]string, 0)
for _, line := range lines {
if matches := r.FindStringSubmatch(line); matches != nil {
vals = append(vals, matches[1], matches[3])
}
}
return carapace.ActionValuesDescribed(vals...)
})
})
}