aboutsummaryrefslogtreecommitdiff
path: root/flag.go
AgeCommit message (Collapse)Author
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.
2016-08-14Use flag's string type in usagebogem
Now in usage shows flag.Value.Type() instead of flag.Value.(type), what makes library more flexible
2016-06-24Removed unused field "exitOnError".Jonathan Barronville
2016-04-27Passthrough flags inserted by go testMoshe Cohen
2016-04-11Add simple method to see if a flagset has available flagsJohn Schnake
With the hidden and deprecated fields, it is useful to be able to ask if a flagset has any non-hdden, non-deprecated flags. One example of this is to aid in writing help templates.
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-23Add more CI checks forcing code cleanlinessEric Paris
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-15Use Type() instead of internal .(*stringValue)Eric Paris
This makes things easier to read/understand and it also means that users who declare their own flags and call them "string" will get quotes as well.
2015-08-15Merge pull request #46 from eparis/goreportcardEric Paris
Fix up minor things found by goreportcard.com
2015-08-15Reduce code duplication in PrintDefaults/FlagUsagesEric Paris
They both did the same thing. So use one in the other.
2015-08-15Fix up minor things found by goreportcard.comEric Paris
2015-08-14Annotate optional flags in usageFuncEric 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-08-05Do not include \n in Errorf outputEric Paris
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-05-27Slight code cleanup parsing long flagsEric Paris
2015-05-12Fixed statementAnastasis Andronidis
2015-05-12Normalization should change the nameAnastasis Andronidis