mirror of
https://github.com/rsteube/carapace-bin.git
synced 2025-05-05 15:32:53 +00:00
mix: added flags and help command
also support user specs for tasks with `mix.<task>.yaml`
This commit is contained in:
parent
4286d32e2e
commit
2f38d8b290
23
completers/mix_completer/cmd/help.go
Normal file
23
completers/mix_completer/cmd/help.go
Normal file
@ -0,0 +1,23 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/carapace-sh/carapace"
|
||||
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/mix"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var helpCmd = &cobra.Command{
|
||||
Use: "help",
|
||||
Short: "prints documentation for a given task",
|
||||
Run: func(cmd *cobra.Command, args []string) {},
|
||||
}
|
||||
|
||||
func init() {
|
||||
carapace.Gen(helpCmd).Standalone()
|
||||
|
||||
rootCmd.AddCommand(helpCmd)
|
||||
|
||||
carapace.Gen(helpCmd).PositionalCompletion(
|
||||
mix.ActionMixTasks(),
|
||||
)
|
||||
}
|
@ -3,6 +3,7 @@ package cmd
|
||||
import (
|
||||
"github.com/carapace-sh/carapace"
|
||||
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/mix"
|
||||
"github.com/carapace-sh/carapace-bridge/pkg/actions/bridge"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -19,8 +20,18 @@ func Execute() error {
|
||||
|
||||
func init() {
|
||||
carapace.Gen(rootCmd).Standalone()
|
||||
rootCmd.Flags().SetInterspersed(false)
|
||||
|
||||
rootCmd.Flags().BoolP("help", "h", false, "show help")
|
||||
rootCmd.Flags().BoolP("version", "v", false, "show version")
|
||||
|
||||
carapace.Gen(rootCmd).PositionalCompletion(
|
||||
mix.ActionMixTasks(),
|
||||
)
|
||||
|
||||
carapace.Gen(rootCmd).PositionalAnyCompletion(
|
||||
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
|
||||
return bridge.ActionCarapaceBin("mix." + c.Args[0]).Shift(1)
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
@ -13,17 +13,15 @@ import (
|
||||
// install
|
||||
// deps.get
|
||||
func ActionMixTasks() carapace.Action {
|
||||
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
|
||||
return carapace.ActionExecCommand("mix", "help")(func(output []byte) carapace.Action {
|
||||
lines := strings.Split(string(output), "\n")
|
||||
r := regexp.MustCompile(`^mix (\S+)\s*# (.*)`)
|
||||
vals := make([]string, 0)
|
||||
for _, line := range lines {
|
||||
if matches := r.FindStringSubmatch(line); matches != nil {
|
||||
vals = append(vals, matches[1], matches[2])
|
||||
}
|
||||
return carapace.ActionExecCommand("mix", "help")(func(output []byte) carapace.Action {
|
||||
lines := strings.Split(string(output), "\n")
|
||||
r := regexp.MustCompile(`^mix (\S+)\s*# (.*)`)
|
||||
vals := make([]string, 0)
|
||||
for _, line := range lines {
|
||||
if matches := r.FindStringSubmatch(line); matches != nil {
|
||||
vals = append(vals, matches[1], matches[2])
|
||||
}
|
||||
return carapace.ActionValuesDescribed(vals...)
|
||||
})
|
||||
})
|
||||
}
|
||||
return carapace.ActionValuesDescribed(vals...)
|
||||
}).Tag("tasks")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user