Commit Graph

83 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
Jesse Szwedko
9073334ecd Fix context.IsSet()
Accidentally mangled the implementation when merging master into the
`v2` branch resulting in a dropped test.
2017-02-14 21:18:40 -08:00
Péter Szilágyi
acc622e5fb
Invalidate context.setFlags cache on modification. 2017-01-11 14:38:54 +02:00
Joshua Rubin
2da42640ad
Merge remote-tracking branch 'origin/master' into completion_fix 2016-11-18 09:28:39 -07:00
Joshua Rubin
8dd1962f7b
change "complete" to "shellComplete" 2016-11-14 09:35:22 -07: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
Joshua Rubin
ea3df26e64
make shell autocomplete more robust 2016-11-04 14:56:28 -06:00
Jesse Szwedko
83497d2cda Merge remote-tracking branch 'origin/master' into v2-merge 2016-10-29 14:13:18 -07:00
Jesse Szwedko
e7b1833f53 Dereference Flags if they are pointers
When checking if environment variables are set.

We don't support pointer flags currently (though this is the default in
the `v2` branch), but this fixes #516
2016-09-08 21:10:46 -07:00
Jesse Szwedko
168c95418e Ensure that EnvVar struct field exists before interrogating it
Otherwise you end up with `<invalid Value>` which, in practice, would
probably work, but this is cleaner.
2016-07-31 20:11:16 -07:00
Jesse Szwedko
6c1f51aa95 Fix context.(Global)IsSet to respect environment variables
This appeared to be the least messy approach to hack in support for
IsSet also checking environment variables to see if a particular
cli.Flag was set without making backwards incompatible changes to the
interface.

I intend to fix this more properly in v2, probably by adding another
method to the cli.Flag interface to push the responsibility down as it
occurred to me that it was really the `Flag`s themselves that offer
support for configuration via the environment as opposed to the
`context` or other supporting structures. This opens the door for the
anything implementing the `Flag` interface to have additional sources of
input while still supporting `context.IsSet`.
2016-07-31 14:14:46 -07:00
Dan Buch
f7b2b93ffa
Merge remote-tracking branch 'origin/v1' into merging-from-v1 2016-07-14 17:50:16 -04:00
Dan Buch
77f1130e65
Generate flag type lookup funcs 2016-07-10 12:50:57 -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
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
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
80d3d863d9 Adding Int64 and GlobalInt64 in context, plus related tests 2016-06-11 15:41:24 -07:00
Dan Buch
3d75e9e711
Go with interfaces + private opaque types
rather than public types that wrap slices
2016-05-25 12:05:14 -04:00
Dan Buch
61710ff108
Make slice wrapping pattern more consistent
and move *Args out into its own file
2016-05-23 20:15:35 -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
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
f2d5ed9933
Replace BoolTFlag type with BoolFlag.Value
Closes #412
2016-05-18 08:20:15 -04:00
Dan Buch
7318e27528
Tidy up the flag name visitor func in Context 2016-05-17 03:46:16 -04:00
Dan Buch
c720f37e15
Context tests and tweaks around lineage traversal
per feedback on #410
2016-05-17 03:16:26 -04:00
Dan Buch
bef835d455
Remove all Context.Global* methods
and change the behavior of the non-Global variants to always search up the
context lineage.

Closes #385
2016-05-16 10:18:15 -04:00
Dan Buch
32ebecfbb5
Merge remote-tracking branch 'origin/master' into v2 2016-05-09 11:18:21 -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
Jesse Szwedko
e3ace79a91 Add GlobalBoolT
Fixes #206
2016-05-07 16:11:26 -07:00
Dan Buch
1fb52b3bce
Merge remote-tracking branch 'origin/master' into string-slice-flag-default-160 2016-04-30 13:13:02 -04:00
Dan Buch
f3b589e892
Remove unreachable code 2016-04-30 12:22:32 -04:00
Dan Buch
e059dc8188
Implement *Context.GlobalSet + relevant CHANGELOG entry 2016-04-30 11:46:47 -04:00
Dan Buch
4edb5c9a6b
Merge branch 'bryanl-set-context-values' of https://github.com/bryanl/cli into bryanl-bryanl-set-context-values 2016-04-30 11:25:05 -04:00
Dan Buch
d1b0c49a98
Ensure slice types can safely round-trip through flag.FlagSet 2016-04-29 02:30:49 -04:00
Dan Buch
bd0f13d022
Add Context.GlobalFloat64 plus tests
Closes #362
2016-04-28 13:03:25 -04:00
Omer Murat Yildirim
802f64479d Add NArg method to context structure 2016-02-21 15:57:11 +02:00
Jille Timmermans
f101a00018 Export cli.Flag.GetName (previously cli.Flag.getName) 2015-12-15 17:29:03 +00:00
Fabian Ruff
a2d4ae5939 Fix global flags processing on top level
This fixes a regression introduced by #227. When looking up global flags by walking up the parent context's we need to consider the special case when we are starting at the very top and there is no parent context to start the traversal.

Fixes #252
2015-06-29 23:20:27 +02:00
Brian Goff
15e6b2fcc7 Add func to get context parent
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2015-06-19 17:06:04 -04:00
bryanl
a3b93076ff Allow context value to be set after parse
This change allows a context value to be set after parsing. The use case is updating default settings in a Before func.

An example usage:

```
		f, err := os.Open(configPath)
		if err == nil {
			config, err := docli.NewConfig(f)
			if err != nil {
                       panic(err)
			}

			c.Set("token", config.APIKey)
		}
```
2015-06-08 16:21:26 -04:00
Fabian Ruff
65d50017d4 search context hierachy for global flags 2015-05-18 23:21:33 +02:00
Ravi Gadde
bcec9b08c7 Added an API and test case for number of flags set 2015-03-10 17:18:12 -07:00
Jeremy Saenz
0cd0f1a3ae Merge pull request #143 from artnez/master
Add Context.GlobalFlagNames()
2014-11-23 13:40:04 -08:00
Jesse Howarth
b490b5e35d Add a function to determine if a global flag is set. 2014-11-11 12:48:07 -08:00
Artem Nezvigin
6db418e461 Add Context.GlobalFlagNames() 2014-10-02 15:17:57 -07:00