Skip to content

Commit 5f2736e

Browse files
authored
Merge pull request #152 from seveas/list-plugins
List plugins in the help output
2 parents fc4016f + 0690927 commit 5f2736e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

cmd/herd/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,23 @@ Providers: %s
118118
currentUser.historyDir,
119119
currentUser.cacheDir,
120120
strings.Join(herd.Providers(), ",")))
121+
hf := rootCmd.HelpFunc()
122+
rootCmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
123+
// Find all plugins in the $PATH and add them to the help output
124+
path := os.Getenv("PATH")
125+
allPlugins := []string{}
126+
for _, dir := range filepath.SplitList(path) {
127+
plugins, _ := filepath.Glob(filepath.Join(dir, "herd-provider-*"))
128+
for _, p := range plugins {
129+
allPlugins = append(allPlugins, strings.TrimPrefix(filepath.Base(p), "herd-provider-"))
130+
}
131+
}
132+
if len(allPlugins) != 0 {
133+
sort.Strings(allPlugins)
134+
rootCmd.SetHelpTemplate(fmt.Sprintf("%sProviders (plugins): %s\n", rootCmd.HelpTemplate(), strings.Join(allPlugins, ",")))
135+
}
136+
hf(cmd, args)
137+
})
121138
cobra.OnInitialize(initConfig)
122139
f := rootCmd.PersistentFlags()
123140
f.Duration("splay", 0, "Wait a random duration up to this argument before and between each host")

0 commit comments

Comments
 (0)