diff --git a/app_test.go b/app_test.go index 798cb0f..5c10dc7 100644 --- a/app_test.go +++ b/app_test.go @@ -262,6 +262,14 @@ func TestBashCompletionOptions(t *testing.T) { return []string{"arg-4-opt-1", "arg-4-opt-2"} }).String() + four := a.Command("four", "") + four.Arg("arg-5", "").ExistingFileOrDir() + four.Arg("arg-6", "").HintOptions("/usr", "/usr/local").ExistingDir() + + five := a.Command("five", "") + five.Flag("flag-5", "").ExistingFile() + five.Command("sub-1", "").Flag("flag-6", "").ExistingDir() + cases := []struct { Args string ExpectedDir bool @@ -270,7 +278,7 @@ func TestBashCompletionOptions(t *testing.T) { }{ { Args: "--completion-bash", - ExpectedWords: []string{"help", "one", "three", "two"}, + ExpectedWords: []string{"five", "four", "help", "one", "three", "two"}, }, { Args: "--completion-bash --", @@ -283,7 +291,7 @@ func TestBashCompletionOptions(t *testing.T) { { // No options available for flag-0, return to cmd completion Args: "--completion-bash --flag-0", - ExpectedWords: []string{"help", "one", "three", "two"}, + ExpectedWords: []string{"five", "four", "help", "one", "three", "two"}, }, { Args: "--completion-bash --flag-0 --", @@ -299,7 +307,7 @@ func TestBashCompletionOptions(t *testing.T) { }, { Args: "--completion-bash --flag-1 opt1", - ExpectedWords: []string{"help", "one", "three", "two"}, + ExpectedWords: []string{"five", "four", "help", "one", "three", "two"}, }, { Args: "--completion-bash --flag-1 opt1 --", diff --git a/clause.go b/clause.go index 50c603a..83d5d49 100644 --- a/clause.go +++ b/clause.go @@ -283,16 +283,20 @@ func (c *Clause) BytesVar(target *units.Base2Bytes) { // ExistingFile sets the parser to one that requires and returns an existing file. func (c *Clause) ExistingFileVar(target *string) { + c.builtinCompletion.Files = true c.SetValue(newExistingFileValue(target)) } // ExistingDir sets the parser to one that requires and returns an existing directory. func (c *Clause) ExistingDirVar(target *string) { + c.builtinCompletion.Directories = true c.SetValue(newExistingDirValue(target)) } // ExistingDir sets the parser to one that requires and returns an existing directory. func (c *Clause) ExistingFileOrDirVar(target *string) { + c.builtinCompletion.Directories = true + c.builtinCompletion.Files = true c.SetValue(newExistingFileOrDirValue(target)) } diff --git a/cmd.go b/cmd.go index 1fcbebc..24b35fc 100644 --- a/cmd.go +++ b/cmd.go @@ -51,7 +51,6 @@ func (c *cmdMixin) CmdCompletion(context *ParseContext) Completion { options.addWords(cmd.name) } } - return options }