aboutsummaryrefslogtreecommitdiff
path: root/flag.go
AgeCommit message (Collapse)Author
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]>
2019-09-17Merge pull request #216 from therealmitchconnors/elegantMitch Connors
Implement SliceValue for better list semantics
2019-09-10Add SliceValue Commentstherealmitchconnors
2019-08-16Add first SliceValue implementationstherealmitchconnors
2019-06-16Fix package docDavid Schneider
Signed-off-by: David Schneider <[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-06-01Allow bubbling up of -test.* flags (#169)Joffrey F
Based on patch suggested here: https://github.com/spf13/cobra/issues/597#issuecomment-385984076
2018-04-12Typo correction in flag.go (#164)v1.0.1Saakallya Biswas
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-04-03make x.Parsed() return true after AddGoFlagSet(x) and pflag.Parse() (#162)childe
* make GoFlagSets.Parsed() true after pflag.Parse some third part lib such as glog use go flag package, and its some actions depends on if goflag.Parsed(). * add test case for goflag.CommandLine.Parsed() * add comment to goflag.CommandLine.Parsed test case
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
2018-03-28Add multiline wrapping support (#155)mkishere
* Add multiline wrapping support With reference to golang/go#20799, pflag now will respect newline in usage string and do wrap accordingly. Also add test cases for testing * Break at \n only if \n pos<wrap
2017-11-06Add uintSlice and boolSlice to name prettifier (#150)Steven Roose
2017-10-20Prevent printing when using ContinueOnError (#144)Steven Roose
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-30Generate flag error output for errors returned from the parseFunc (#138)Michael Porter
2017-09-01New: renamed intSlice to ints in usageChristophe Serafin
2017-09-01New: added a default name to avoid stringSlice in the usage message.Christophe Serafin
2017-05-05Testing for Shorthand LookupEric Paris
2017-05-05Add example to ShorthandLookupAlbert Nigmatzianov
2017-05-05Add note about panic in ShorthandLookupAlbert Nigmatzianov
2017-05-05Allow lookup by shorthand (#106)Charlie R.C
2017-04-27Unify error message for panic and f.outAlbert Nigmatzianov
2017-04-26Use comparison a string with "" instead of comparison of lenAlbert Nigmatzianov
2017-04-26Prevent parsing if there are no argumentsAlbert Nigmatzianov
2017-04-26Add more verbosity to panic of shorthand redefinitionAlbert Nigmatzianov
See https://github.com/spf13/cobra/issues/27#issuecomment-294690084
2017-04-26Use f.out in output flag deprecationAlbert Nigmatzianov
2017-04-26Make more detailed error in SetAlbert Nigmatzianov
2017-04-26Add comments for better understanding of parsing short flagsAlbert Nigmatzianov
2017-04-26Delete setFlagAlbert Nigmatzianov
2017-04-26Fix alreadythere variable nameAlbert Nigmatzianov
In some cases "exists" is better to understand
2017-04-18Merge pull request #119 from bogem/cachesortedeAlbert Nigmatzianov
Cache sorted flags
2017-04-17Merge pull request #75 from jonathanmarvens/patch-1Albert Nigmatzianov
Removed unused field "exitOnError".
2017-04-17Merge pull request #116 from bogem/fixdocsAlbert Nigmatzianov
Change `ogier` to `spf13` in docs and README
2017-04-05Cache sorted flagsAlbert Nigmatzianov
As you can't delete flags in FlagSet, this method works Gainful performance improvement: benchmark old ns/op new ns/op delta BenchmarkVisitAll10Flags-4 1549 33.9 -97.81% BenchmarkVisit10Flags-4 1704 34.2 -97.99% benchmark old allocs new allocs delta BenchmarkVisitAll10Flags-4 3 0 -100.00% BenchmarkVisit10Flags-4 3 0 -100.00% benchmark old bytes new bytes delta BenchmarkVisitAll10Flags-4 272 0 -100.00% BenchmarkVisit10Flags-4 272 0 -100.00%
2017-04-05Prevent changing order of flags after SetNormalizeFunc() (#121)Albert Nigmatzianov
Fix #120
2017-03-27Modified to display a string default value as double quoted and escaped (#118)Matthew Winter
2017-03-25Add SortFlags option (#113)Albert Nigmatzianov
Fixes https://github.com/spf13/cobra/issues/316
2017-03-25Change `ogier` to `spf13` in docs and READMEAlbert Nigmatzianov
2017-01-30Add FlagSet.FlagUsagesWrapped(cols) which wraps to the given column (#105)Ian Campbell
This will allow applications to provide better help text without feeling constrained by how it will wrap even on 80 column displays etc. This has been a factor in tickets such as https://github.com/docker/docker/issues/18797. The basic wrapping algorithm is rather simplistic, it will look for the last whitespace (space or tab) before the given column and wrap there, indenting the continuation lines to match the usage text (i.e. aligned after the flag names themselves), e.g. when applied to `docker ps` wrapping at 70 columns (fairly narrow): Options: [...] -f, --filter filter Filter output based on conditions provided [...] -n, --last int Show n last created containers (includes all states) (default -1) -l, --latest Show the latest created container (includes all states) There are two main tweaks to this basic algorithm, first is to actually try and wrap to a soft limit 5 columns less than requested but allow the line to take up the full hard width if that prevents pushing a short word at the end of the string to the next line which looks odd, particuarly for usage which ends with "(default [])" and wraps the "[])" to the last line. Second if the display is too narrow, meaning after indentation for the flag names there is less than 24 columns allowed for the help text (24 chosen just by my eye and what I thought looked odd) then it will start the help text on the next line indented to the 16th column (16 chosen so as not to align with the first character of either the short of long flag name as 8 would, since that looked strange to me), e.g. wrapping the above example to a rather narrow 45 columns: Options: [...] -f, --filter filter Filter output based on conditions provided [...] -n, --last int Show n last created containers (includes all states) (default -1) -l, --latest Show the latest created container (includes all states) If even with starting the help on the next line there is still less than 24 characters of space available for the help text (implying columns < 24 + 16 == 40) just give up and return the unwrapped version (same as before this change). Signed-off-by: Ian Campbell <[email protected]>,
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-10-18Don't print escaped strings for the default value of string flags with a ↵Daniel Nephin
default is set. Signed-off-by: Daniel Nephin <[email protected]>
2016-10-18Don't print escaped strings for the default value of string flags.Daniel Nephin
Signed-off-by: Daniel Nephin <[email protected]>
2016-09-25Optimize fmt statementsbogem
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.