-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
tool.go
47 lines (39 loc) · 1.29 KB
/
tool.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/golang"
"github.com/carapace-sh/carapace-bridge/pkg/actions/bridge"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
var toolCmd = &cobra.Command{
Use: "tool",
Short: "run specified go tool",
Run: func(cmd *cobra.Command, args []string) {},
}
func init() {
carapace.Gen(toolCmd).Standalone()
toolCmd.Flags().SetInterspersed(false)
toolCmd.Flags().StringS("C", "C", "", "Change to dir before running the command")
toolCmd.Flags().BoolS("n", "n", false, "only print the command that would be executed")
rootCmd.AddCommand(toolCmd)
carapace.Gen(toolCmd).FlagCompletion(carapace.ActionMap{
"C": carapace.ActionDirectories(),
})
carapace.Gen(toolCmd).PositionalCompletion(
golang.ActionTools(),
)
carapace.Gen(toolCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
switch c.Args[0] {
case "pprof":
return bridge.ActionCarapaceBin(c.Args[0]).Shift(1)
default:
return bridge.ActionCarapaceBin("go-tool-" + c.Args[0]).Shift(1)
}
}),
)
carapace.Gen(toolCmd).PreInvoke(func(cmd *cobra.Command, flag *pflag.Flag, action carapace.Action) carapace.Action {
return action.Chdir(cmd.Flag("C").Value.String())
})
}