Commit Graph

108 Commits

Author SHA1 Message Date
Dan Buch
65b801c818
Resolve remaining test errors for v1 => v2 merge 2017-08-12 22:02:54 -04:00
Dan Buch
47a412375f
Resolved compile-time errors since merging from v1 2017-08-04 12:00:22 -04:00
Dan Buch
a61867e5e6
Merge remote-tracking branch 'origin/v1' into merging-from-v1 2017-08-04 11:59:27 -04:00
Joe Richey joerichey@google.com
1794792adf Add ability to use custom Flag types
Users can now use custom flags types (conforming to the Flag interface)
in their applications. They can also use custom flags for the three
global flags (Help, Version, bash completion).
2017-05-05 22:24:14 -07:00
Jesse Szwedko
d71794de19 Make ApplyWithError a public method on errorableFlag
Add to altsrc flags. Otherwise, flagSet() was bypassing altsrc's attempt
at shadowing.
2016-11-19 10:51:20 -08:00
drekar
4661a59b20 errorableFlag: scope result of type assertion. 2016-11-17 09:48:03 -10:00
Jesse Szwedko
e367fafa3d Return an error when parsing environment variables for values fails
Currently cli silently (aside from IntSlice and Int64Slice which oddly
printed directly to the error stream) ignores failures that occur when
parsing environment variables for their value for flags that define
environment variables. Instead, we should propogate up the error to the
user.

This is accomplished in a backwards compatible manner by adding a new,
internal, interface which defines an applyWithError function that all
flags here define. In v2, when we can modify the interface, we can drop
this secondary interface and modify `Apply` to return an error.
2016-11-13 14:59:35 -08:00
Jesse Szwedko
a00c3f5872 Consider empty environment variables as set
When assigning values to flags (also when interogatting via
`context.(Global)IsSet`.

For boolean flags, consider empty as `false`.

Using `syscall.Getenv` rather than `os.LookupEnv` in order to support
older Golang versions.
2016-11-13 14:59:27 -08:00
Jesse Szwedko
83497d2cda Merge remote-tracking branch 'origin/master' into v2-merge 2016-10-29 14:13:18 -07:00
Antonio Murdaca
c516bce8f1
flags: provide a type to sort flags
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-10-21 10:37:18 +02:00
lewo
6aa0ab6903 Merge branch 'v2' into v2-completion 2016-09-01 09:35:02 +02:00
Jake Champlin
7d56512ecc
Add documentation, remove quotes by default 2016-08-30 10:52:24 -04:00
Jake Champlin
e0556cf9e8
Add DefaultValue text for flags
Allows a user to override the default value of a flag in the displayed help output.

Ex:
```
cli.IntFlag{
	Name: "foo, f",
	DefaultText: "random foo",
	Value: "bar",
}
```

Running `(app.name) -h` will now yield:

```
--foo value     (default: "random foo")
```

Fixes: #504
2016-08-28 03:14:39 -04:00
Antoine Eiche
94bc26fd1c Refactoring names from bash to shell
The refactoring is required since completion is also supported for zsh
shell.

Refactoring details:
- flag generate-bash-completion -> generate-completion
- var  EnableBashCompletion     -> EnableShellCompletion
- var  BashComplete             -> ShellComplete
- var  BashCompletionFlag       -> GenerateCompletionFlag
- type BashCompleteFunc         -> ShellCompleteFunc
2016-07-26 15:32:03 +02:00
Antoine Eiche
7640bef0eb Add --init-completion flag to print completion code
This flag takes as input 'bash' or 'zsh' and generates the completion
code for the specified shell.
2016-07-26 15:32:03 +02:00
Dan Buch
f7b2b93ffa
Merge remote-tracking branch 'origin/v1' into merging-from-v1 2016-07-14 17:50:16 -04:00
Bruno França dos Reis
028af4bc35 adding support for Float64SliceFlag 2016-06-28 19:52:25 -07:00
Dan Buch
6185b8d8fd
Generate code for flag types and context accessors 2016-06-23 00:56:44 -04:00
Dan Buch
0c9b549918
Ensure remaining v1 additions are v2 compatible 2016-06-17 09:54:54 -04:00
Dan Buch
6c628a1a88
Merge remote-tracking branch 'origin/v1' into merging-from-v1 2016-06-17 09:11:36 -04:00
Dan Buch
a0e694ed72
Add UintFlag, Uint64Flag types and supporting code 2016-06-16 11:13:32 -04:00
Dan Buch
537f5beb66
Tweaks to Int64Flag PR 2016-06-16 10:14:28 -04:00
Bruno França dos Reis
5c7cca7f16 Adding Int64Slice related stuff in flag.go and context.go, and related tests 2016-06-11 21:54:33 -07:00
Bruno França dos Reis
4962423cba Adding Int64Flag type and related tests 2016-06-11 15:22:07 -07:00
Dan Buch
7cd5bed6cb
Backporting flagValue func from v2 branch 2016-06-08 10:34:44 -04:00
Joshua Rubin
f621deee5a
fix panic getting visible flags 2016-06-08 04:27:57 -06:00
3b03164c92 Merge branch 'v2' into show-bool-default 2016-05-28 04:49:10 -04:00
Dan Buch
cd1e8c3452
Merge remote-tracking branch 'origin/v2' into minimize-struct-copying 2016-05-25 09:35:21 -04:00
Dan Buch
2b288769c7
Add comment about commaWhitespace stripping of flag.Name 2016-05-24 04:00:37 -04:00
c70993dbc5 Merge branch 'v2' into minimize-struct-copying 2016-05-23 22:08:59 -04:00
80f444e0f5 Merge branch 'v2' into clean-stringlies 2016-05-23 22:08:42 -04:00
Dan Buch
8f25dbb615
Ensure all flag aliases are set when Destination given
and extend "Incorrect Usage" message to show the error.

Closes #430
2016-05-23 22:00:59 -04:00
Dan Buch
ec05a8d31b
Ensure flag "Name" field values are un-stringly-fied
to (hopefully) help with bug triage & pinpointing usage issues since ripping out
stringly typed "Name".
2016-05-23 20:55:03 -04:00
Dan Buch
cd10b49473
Minimize struct copying
by using pointer func receivers and slices of struct pointers where possible.
2016-05-22 15:20:52 -04:00
Dan Buch
334e66cb8f
Remove unused (so far) func 2016-05-22 10:59:42 -04:00
Dan Buch
81fcf706ea
Replace all "stringly typed" fields with slice equivalents
and alter the Flag interface accordingly

Closes #415
2016-05-21 21:29:45 -04:00
Dan Buch
fac67ac91a
Show BoolFlag default value in help usage
now that BoolTFlag is gone
2016-05-21 20:02:08 -04:00
Dan Buch
f2d5ed9933
Replace BoolTFlag type with BoolFlag.Value
Closes #412
2016-05-18 08:20:15 -04:00
Dan Buch
32ebecfbb5
Merge remote-tracking branch 'origin/master' into v2 2016-05-09 11:18:21 -04:00
Matt Farina
07ce8bf79c Cleaned up else per golint
When an if ends in a return the else is not required. golint
detects these conditions and found these.
2016-05-09 10:15:05 -04:00
Matt Farina
2f110bd745 Cleaned up exported func comments per golint 2016-05-09 10:12:59 -04:00
Dan Buch
bac790c819
Merge remote-tracking branch 'origin/master' into v2 2016-05-09 08:00:13 -04:00
Matt Farina
6f0b442222 Update to ErrWriter and make available on app 2016-05-06 12:14:26 -04:00
Matt Farina
2a256d4c53 Provide a variable for writing output with a default of os.Stderr 2016-05-05 10:26:53 -04:00
Dan Buch
a1e5328e30
Merge remote-tracking branch 'origin/master' into string-slice-flag-default-160 2016-05-03 05:25:07 -04:00
Dan Buch
cd92adcb75
Further simplifying default flag stringer func 2016-05-02 19:58:16 -04:00
Dan Buch
6089d723a8
Use existing prefixedNames func 2016-05-02 19:52:39 -04:00
Dan Buch
69a8e25f3d
Make flag usage rendering more consistent; show default values 2016-05-02 19:42:08 -04:00
Dan Buch
23af5dd643
Rename flag stringer func bits for clarity, consistency 2016-05-02 13:07:57 -04:00
Dan Buch
22773b14c1
Allow for pluggable flag-level help text formatting
by defining `cli.DefaultFlagStringFunc` with a default value that uses
`withEnvHint`, conditionally running a given flag's `FormatValueHelp` if
present.

Closes #257
2016-05-02 13:05:21 -04:00