-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/carapace-sh/carapace" | ||
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/mix" | ||
"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() | ||
|
||
carapace.Gen(rootCmd).PositionalCompletion( | ||
mix.ActionMixTasks(), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// 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.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.ActionValuesDescribed(vals...) | ||
}) | ||
}) | ||
} |