completion should suggest directories if use contains DIR

This commit is contained in:
Phillip Wittrock
2019-12-21 16:04:23 -08:00
parent a280cdf5ee
commit 8a1874d20d
2 changed files with 5 additions and 1 deletions

View File

@@ -52,6 +52,10 @@ func Complete(cmd *cobra.Command) *complete.Command {
Flags: map[string]complete.Predictor{},
Sub: map[string]*complete.Command{},
}
if strings.Contains(cmd.Use, "DIR") {
// if usage contains directory, then use a file predictor
cc.Args = predict.Dirs("*")
}
// add completion for each subcommand
for i := range cmd.Commands() {

View File

@@ -14,7 +14,7 @@ import (
func GetFmtRunner(name string) *FmtRunner {
r := &FmtRunner{}
c := &cobra.Command{
Use: "fmt",
Use: "fmt DIR...",
Short: commands.FmtShort,
Long: commands.FmtLong,
Example: commands.FmtExamples,