-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #963 from rsteube/fix-flagparsing-disabled
FlagParsingDisabled: fix positional completion
- Loading branch information
Showing
3 changed files
with
56 additions
and
1 deletion.
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
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,24 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/rsteube/carapace" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var flag_disabledCmd = &cobra.Command{ | ||
Use: "disabled", | ||
Short: "flag parsing disabled", | ||
DisableFlagParsing: true, | ||
Run: func(cmd *cobra.Command, args []string) {}, | ||
} | ||
|
||
func init() { | ||
carapace.Gen(flag_disabledCmd).Standalone() | ||
|
||
flagCmd.AddCommand(flag_disabledCmd) | ||
|
||
carapace.Gen(flag_disabledCmd).PositionalCompletion( | ||
carapace.ActionValues("-p1", "positional1"), | ||
carapace.ActionValues("p2", "--positional2"), | ||
) | ||
} |
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,27 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/rsteube/carapace" | ||
"github.com/rsteube/carapace/pkg/sandbox" | ||
) | ||
|
||
func TestFlagDisabled(t *testing.T) { | ||
sandbox.Package(t, "github.com/rsteube/carapace/example")(func(s *sandbox.Sandbox) { | ||
s.Run("flag", "disabled", ""). | ||
Expect(carapace.ActionValues( | ||
"-p1", | ||
"positional1", | ||
)) | ||
|
||
s.Run("flag", "disabled", "-p1", ""). | ||
Expect(carapace.ActionValues( | ||
"p2", | ||
"--positional2", | ||
)) | ||
|
||
s.Run("flag", "disabled", "-p1", "p2", ""). | ||
Expect(carapace.ActionValues()) | ||
}) | ||
} |