-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make negatable flag name customisable (#439)
* fix: Check if negatable duplicates another flag Add a check for flags with the `negatable` option if the negative flag conflicts with another tag, such as: Flag bool `negatable:""` NoFlag bool The flag `--no-flag` is ambiguous in this scenario. * feat: Make negatable flag name customisable Allow a value on the `negatable` tag to specify a flag name to use for negation instead of using `--no-<flag-name>` as the flag. e.g. Approve bool `default:"true",negatable:"deny"` This example will allow `--deny` to set the `Approve` field to false.
- Loading branch information
Showing
8 changed files
with
128 additions
and
49 deletions.
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
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
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
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,19 @@ | ||
package kong | ||
|
||
// negatableDefault is a placeholder value for the Negatable tag to indicate | ||
// the negated flag is --no-<flag-name>. This is needed as at the time of | ||
// parsing a tag, the field's flag name is not yet known. | ||
const negatableDefault = "_" | ||
|
||
// negatableFlagName returns the name of the flag for a negatable field, or | ||
// an empty string if the field is not negatable. | ||
func negatableFlagName(name, negation string) string { | ||
switch negation { | ||
case "": | ||
return "" | ||
case negatableDefault: | ||
return "--no-" + name | ||
default: | ||
return "--" + negation | ||
} | ||
} |
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