Commit Graph

45 Commits

Author SHA1 Message Date
Ajitem Sahasrabuddhe
f8bb66ae7d
Fix Typo 2019-09-11 14:42:38 +05:30
Ajitem Sahasrabuddhe
c6ee3b4904
Use iterative logic to determine missing flag 2019-09-11 14:34:41 +05:30
Ajitem Sahasrabuddhe
cbb9e015b8
Improve Code and Add Test Case 2019-09-11 09:21:45 +05:30
Ajitem Sahasrabuddhe
fdba7e0f8c
linter fixes
code cleanup
changing some test code to ensure uniformity
2019-08-07 20:14:50 +05:30
Ajitem Sahasrabuddhe
f8ba505a7c
Merge branch 'master' into required-flags-take-2 2019-08-02 22:49:29 +05:30
Lynn Cyrin
d7ec4e8013
add env var tests 2019-08-01 23:27:38 -07:00
Lynn Cyrin
38f9e1622d
add environment variable support 🎉 2019-08-01 22:52:21 -07:00
Lynn Cyrin
cdc7af744e
add handling for multiple required flags 2019-07-17 00:16:40 -07:00
Lynn Cyrin
550ed20ea4
update tests 2019-07-13 01:26:47 -07:00
Ben Zvan
4a76377775 go fmt 2018-12-26 12:48:12 -06:00
Ben Zvan
d63733fe14 adds test coverage to context 2018-12-26 12:45:34 -06:00
Péter Szilágyi
acc622e5fb
Invalidate context.setFlags cache on modification. 2017-01-11 14:38:54 +02:00
Jesse Szwedko
b4a64dc08d Add windows implementation of Clearenv for tests
Apparently `Clearenv` in Windows just sets the variables to ""
2016-11-13 14:59:35 -08: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
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
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
80d3d863d9 Adding Int64 and GlobalInt64 in context, plus related tests 2016-06-11 15:41:24 -07:00
Matt Farina
2f4ec31264 Fixed spelling and gofmt issues 2016-05-09 09:40:09 -04:00
Jesse Szwedko
e3ace79a91 Add GlobalBoolT
Fixes #206
2016-05-07 16:11:26 -07: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
4cae17cfe1
Ensure MultiError returned when both Before and After funcs given 2016-04-28 17:15:16 -04:00
Dan Buch
61d4175525
Merge remote-tracking branch 'origin/master' into txgruppi-develop 2016-04-28 16:20:02 -04:00
Dan Buch
2c0e13ecf8
Revising/adding tests that assert order of operations inside App.Run 2016-04-28 16:05:14 -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
Edward Sheffler III
8ea1232ede Improve vendoring options by removing self-referential imports in tests. 2015-07-20 12:28:51 -07: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
Jesse Howarth
a6bafbe9a5 Add additional test 2014-11-11 12:50:40 -08:00
Jesse Howarth
b490b5e35d Add a function to determine if a global flag is set. 2014-11-11 12:48:07 -08:00
Ghislain Gt
98af61a59f Add time.Duration flag type 2014-08-02 22:32:32 +01:00
Chris Winslett
c69522c960 Make Command accessible from Context 2014-03-29 12:02:05 -07:00
Yicheng Qin
5903a0a844 Add BoolTFlag type
Compared to BoolFlag type, BoolTFlag treats 'true' as the default value
for the flag.

Without it, we have to use --no-action flag if we set the action is done
in default. But sometimes it is bad to maintain flags with negative meanings.
And it will be painful if we change the default value for the flag.

As this implementation, it keeps all existing functionality. So it
is compatible with old versions.
2014-03-05 17:24:22 -08:00
fraenkel
f88df0aa5a Allow optional flags by asking if its been set/present on the command line 2013-12-18 12:09:16 -06:00
Jeremy Saenz
70eacca641 JMS #25: Added support for help flags 2013-07-24 07:35:45 -07:00
Jeremy Saenz
e14e45d087 More test tweaking 2013-07-20 15:53:25 -07:00
Jeremy Saenz
6664835bc1 JMS #14: Moving toward having and app object 2013-07-19 08:34:01 -07:00
Jeremy Saenz
59b0ce24ef JMS #4: Support for global flags in cli.Context 2013-07-18 18:00:52 -07:00
Jeremy Saenz
3119b075d6 JMS #4: Flag testing 2013-07-18 17:41:22 -07:00
Jeremy Saenz
3f76896c4f JMS #4: Getting some cli tests going. Testing out flags 2013-07-18 17:41:22 -07:00
Jeremy Saenz
6f22315082 JMS #4: Parsing command flags with context 2013-07-18 17:41:22 -07:00