aboutsummaryrefslogtreecommitdiff
path: root/flag_test.go
AgeCommit message (Collapse)Author
2025-10-05Show 'correct' explicit bool value syntax in helpAli Mohammad Pur
2025-09-01fix: Restore ParseErrorsWhitelist name for nowTomas Aschan
This will be removed in a future release, but is reintroduced here to not break backwards compatibility.
2025-08-29Reset args on re-parse even if emptyreset-args-even-if-emptyTomas Aschan
This ensures fs.Args() returns the expected thing after every parse. Fixes #439.
2025-07-17Merge pull request #261 from dubrie/masterTomas Aschan
Switching from whitelist to Allowlist terminology. Fixes #294
2025-06-01Merge pull request #409 from ShawnJeffersonWang/masterTomas Aschan
fix: correct argument length check in FlagSet.Parse
2025-04-21test: Commonly-returned error messagesEthan P.
Add tests to ensure invalid arguments and unknown flag error messages don't change.
2025-04-01Improve readability for error in TestPrintDefaultsMidnightRocket
2025-04-01Add better test for defaultIsZeroValue for generic Value typeMidnightRocket
2025-01-09fix govetMark Sagi-Kazar
Signed-off-by: Mark Sagi-Kazar <[email protected]>
2024-12-05fix: add test for argument length checkshawn
2020-06-10Update flag_test.goBill Johnson
2020-05-04Add exported functions to preserve `pkg/flag` compatibility (#220)Ryan McKern
* Rename out() to Output() This brings behavior inline with go's flag library, and allows for printing output directly to whatever the current FlagSet is using for output. This change will make it easier to correctly emit output to stdout or stderr (e.g. a user has requested a help screen, which should emit to stdout since it's the desired outcome). * improve compat. with pkg/flag by adding Name() pkg/flag has a public `Name()` function, which returns the name of the flag set when called. This commit adds that function, as well as a test for it. * Streamline testing Name() Testing `Name()` will move into its own explicit test, instead of running inline during `TestAddFlagSet()`. Co-authored-by: Chloe Kudryavtsev <[email protected]> Co-authored-by: Chloe Kudryavtsev <[email protected]>
2018-08-31Fix panic when parsing unknown flag followed by empty argument (#173)v1.0.3Oren Shomron
Signed-off-by: Oren Shomron <[email protected]>
2018-04-10Allow Users To Show Deprecated Flags (#163)Eric Paris
They have to explicitly unhide a deprecated flag to keep the current behavior.
2018-03-30add ability to ignore unknown flags (#160)Rajat Jindal
* add ability to ignore unknown flags * add testcases * add 2 more patterns to the testcase * handle --unknownflag=val arg and -u=val arg scenario * add ParseErrorsWhiteList to extend error handling during parsing
2017-10-20Prevent printing when using ContinueOnError (#144)Steven Roose
2017-10-16add int16 flag (#143)Matthew Jaffee
* add int16 flag copied int32.go to int16.go and s/32/16 added a case to testParse in flag_test.go * test the set value of int16 flag
2017-10-08Remove redundant breakPontus Leitzler
2017-10-05Fixing Count flag usage string (#141)gonix
2017-10-02Fix SetNormalizeFunc (#137)Diego Becciolini
Related to https://github.com/spf13/cobra/issues/521
2017-09-01New: renamed intSlice to ints in usageChristophe Serafin
2017-09-01Fixed: updated unittestChristophe Serafin
2017-05-05Testing for Shorthand LookupEric Paris
2017-05-05Allow lookup by shorthand (#106)Charlie R.C
2017-04-12flag_test: fix go vet (#123)Tamir Duberstein
flag_test.go:338: result of fmt.Errorf call not used flag_test.go:377: no formatting directive in Errorf call
2017-04-05Prevent changing order of flags after SetNormalizeFunc() (#121)Albert Nigmatzianov
Fix #120
2017-03-25Add SortFlags option (#113)Albert Nigmatzianov
Fixes https://github.com/spf13/cobra/issues/316
2017-01-19Merge pull request #102 from bogem/redundantEric Paris
Clean up code
2017-01-16Make command line parsing available outside pflagxilabao
We basically want to allow callers to use our command line parser. There is a user who wants to log the command line, but they don't want to log "sensitive" flags. This allows that user to parse the command line and get each flag. They can use information in the flag to write their own printer.
2016-10-23Clean up codebogem
2016-09-09Fix default values for custom fieldsCameron Moore
Fallback to the original default detection logic if we have an unknown type. Fixes #91
2016-09-06add a new type StringArraywu8685
2016-08-16Refactor default value detectionCameron Moore
In Go 1.7 the default value for a time.Duration will change from "0" to "0s". This commit replaces the simplistic `isZeroValue` with a more intelligent implementation that checks for zero values based upon the specific type of the flag.
2015-12-18Issue #55: implement Go 1.5-style default usage formatting.Giovanni Bajo
Compare to 1.4, the main difference in formatting is the placement of default values. Moreover, UnquoteUsage() is now added (and exported, for full API compatibility with the standard flag package), so backtick words in usage messages can be used to set the placeholder name. Compared to the standard flag package, this patch always prints usage in one-line, with automatic alignment, because I feel that the 1.4 output is very confusing when modified to include also dash-dash flags.
2015-09-16Store the length of Args when a -- is found in commandlineEric Paris
This allows a program to know what args came before the -- and what args came after.
2015-09-07adding a private field to flags, and a function for marking flags as privateSteve Domino
removing some c/p left-overs from the MarkPrivate function, and updating the comment slightly changed field from Private to Hidden. Added documentation w/example to README.md. Added testing to confirm hidden flags updating test message
2015-08-20Add shorthand deprecatorJanet Kuo
2015-08-15New AddFlagSet function on FlagSetEric Paris
This function allows one to create a different FlagSets and then easily merge them together.
2015-08-15Fix up minor things found by goreportcard.comEric Paris
2015-08-07More tests for ChangedEric Paris
2015-08-07New helper to easily see if a flag has been setEric Paris
A lot easier than having to do it in the user over and over and over.
2015-06-22Add support for '--flag arg'Eric Paris
2015-06-22Set default values if no arg givenEric Paris
2015-06-22Merge pull request #25 from eparis/GetFlagTypeEric Paris
Add new FlagSet.Get{Int,String,...} accessor functions
2015-06-22Add SetAnnotation helperJordan Liggitt
2015-06-01Add new FlagSet.Get{Int,String,...} accessor functionsEric Paris
If I declared a bool flag named "hello" I can now call b, err := f.GetBool("hello") And b will hold the value of the flag We can see this is already done in https://github.com/codegangsta/cli/blob/bcec9b08c7e5564f7512ad7e7b03778fe1923116/context.go If people use the codegangsta/cli Other projects have done it themselves using pflags (what inspired this patch) https://github.com/GoogleCloudPlatform/kubernetes/blob/cd817aebd848facda29e0befbbd6e31bf22402e6/pkg/kubectl/cmd/util/helpers.go#L176 Lets just do it ourselves...
2015-06-01Moar flag_test!Eric Paris
2015-05-19Added a test for normalizing usage nameAnastasis Andronidis
[close #23]
2015-05-10Call normalizeFlagName function only onceAnastasis Andronidis
2015-05-08Support bool= with shortnamesEric Paris
Currently a shortname bool variable b cannot use the -b=true -b=false form because the -b is assumed to mean true and the = format is never noticed.