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 mix completer #2607

Merged
merged 2 commits into from
Nov 26, 2024
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
23 changes: 23 additions & 0 deletions completers/mix_completer/cmd/help.go
Original file line number Diff line number Diff line change
@@ -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(),
)
}
37 changes: 37 additions & 0 deletions completers/mix_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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"
)

var rootCmd = &cobra.Command{
Use: "mix",
Short: "A build automation tool for working with applications written in the Elixir programming language",
Long: "https://hexdocs.pm/mix/Mix.html",
Run: func(cmd *cobra.Command, args []string) {},
}

func Execute() error {
return rootCmd.Execute()
}

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)
}),
)
}
7 changes: 7 additions & 0 deletions completers/mix_completer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/carapace-sh/carapace-bin/completers/mix_completer/cmd"

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

import (
"regexp"
"strings"

"github.com/carapace-sh/carapace"
)

// ActionMixTasks completes mix tasks
//
// install
// deps.get
func ActionMixTasks() 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.ActionValuesDescribed(vals...)
}).Tag("tasks")
}