Commit Graph

123 Commits

Author SHA1 Message Date
Joseph Cumines
e77dd7bb68 Add SliceFlag wrapper and fix bugs in existing implementations
The SliceFlag implementation and associated aliases (MultiStringFlag, etc)
extend the existing slice implementations (StringSliceFlag, etc) to support
actual slices as the flag value and destination.

This change also fixes various bugs in the existing implementation. Notably,
the StringSliceFlag.Apply implementation would modify the input (default)
Value, if an env var was set, and no destination was provided. The bugs fixed
in the other three implementations were all already fixed in either
StringSliceFlag, or in one case (ignoring empty env var) in Float64SliceFlag.
2022-06-07 08:54:57 +10:00
04f5ff0315
Merge branch 'main' into mostynb-report_source_of_parse_errors 2022-05-07 08:57:48 -04:00
e7db6af492
Merge remote-tracking branch 'origin/main' into mostynb-report_source_of_parse_errors 2022-04-30 14:19:06 -04:00
8cc43782ed
Merge branch 'main' into feature/1316-simplified_flag_value_access 2022-04-26 08:12:17 -04:00
6538e95d65
Merge branch 'ally_fix_multi_val' of ssh://github.com/vipally/cli into vipally-ally_fix_multi_val 2022-04-25 22:45:39 -04:00
Kacper Bąk
4c7b46cb24 fix: clean code 2022-04-25 19:11:11 +02:00
Tilo Prütz
835bd32714 rename flags’ ValueFromContext() to Get() 2022-04-25 07:59:10 +02:00
c864c2425e
Merge pull request #1260 from dearchap/issue_1254
Add test case for short option handling
2022-04-24 08:25:02 -04:00
Naveen Gogineni
8c5f1fb359 Changes from code review 2022-04-23 19:30:34 -04:00
Naveen Gogineni
156d47e696 Fix: (issue#1254) short options handling needs to proceed from last terminated error 2022-04-23 19:26:24 -04:00
Tilo Prütz
ca7f26ecb0 Uint64Flag.ValueFromContext() as convenient accessor 2022-04-22 17:11:43 +02:00
Tilo Prütz
1f621059d3 UintFlag.ValueFromContext() as convenient accessor 2022-04-22 17:11:43 +02:00
Tilo Prütz
889c7b5d7a TimestampFlag.ValueFromContext() as convenient accessor 2022-04-22 17:11:43 +02:00
Tilo Prütz
6b336c478f StringSliceFlag.ValueFromContext() as convenient accessor 2022-04-22 17:11:43 +02:00
Tilo Prütz
ce4d9279c4 StringFlag.ValueFromContext() as convenient accessor 2022-04-22 17:11:43 +02:00
Tilo Prütz
660184dd92 PathFlag.ValueFromContext() as convenient accessor 2022-04-22 17:11:43 +02:00
Tilo Prütz
6d7f859008 IntSliceFlag.ValueFromContext() as convenient accessor 2022-04-22 17:11:43 +02:00
Tilo Prütz
dcc47855b8 Int64SliceFlag.ValueFromContext() as convenient accessor 2022-04-22 17:11:43 +02:00
Tilo Prütz
18b44dfb29 Int64Flag.ValueFromContext() as convenient accessor 2022-04-22 17:11:43 +02:00
Tilo Prütz
bf18c00347 IntFlag.ValueFromContext() as convenient accessor 2022-04-22 17:11:43 +02:00
Tilo Prütz
8bd5fb2390 GenericFlag.ValueFromContext() as convenient accessor 2022-04-22 17:11:43 +02:00
Tilo Prütz
2f92fc644c Float64SliceFlag.ValueFromContext() as convenient accessor 2022-04-22 17:11:43 +02:00
Tilo Prütz
5047beb001 Float64Flag.ValueFromContext() as convenient accessor 2022-04-22 17:11:43 +02:00
Tilo Prütz
9eae255aac DurationFlag.ValueFromContext() as convenient accessor 2022-04-22 17:11:43 +02:00
Tilo Prütz
baf8ae98de BoolFlag.ValueFromContext() as convenient accessor 2022-04-22 17:11:43 +02:00
9fd3cc92ad
Add tests around flag stringifying for all modified types 2022-04-21 23:02:44 -04:00
d83bb8d85e
Merge branch 'main' into remove_reflect 2022-04-21 20:22:26 -04:00
826b3edd3f
Merge branch 'report_source_of_parse_errors' of ssh://github.com/mostynb/cli into mostynb-report_source_of_parse_errors 2022-04-19 19:41:57 -04:00
Ally Dale
58d113dd73
fix #1239: slice flag value don't append to default values from ENV or file (#1240)
* fix #1239: slice flag value don't append to default values from ENV or file

* remove test code
2021-07-06 20:33:01 -04:00
Naveen Gogineni
7cd7ff7dd5 Remove reflect from flag_test 2021-04-28 20:50:29 -04:00
Robert Liebowitz
ab52d6f3a9 Merge branch 'master' into ally_fix_default_val 2021-04-24 12:59:13 -04:00
David Bond
f2bed637fd
Add Destination field to TimestampFlag
Adds a `Destination` field for the `TimestampFlag` type that allows you to specify a pointer to
a `Timestamp` rather than having to grab the `Timestamp` from the `cli.Context` using the flag
name.
2021-03-07 03:36:56 +00:00
Ally Dale
ef9430e77e fix #1238: accept multi-value input on sclice flags 2021-02-08 20:10:28 +08:00
AllyDale
c98b85d392 bug fix #1235 : default value changes with parsed values on slice flags 2021-02-05 15:16:50 +08:00
Robert Liebowitz
795a8adacb
Merge pull request #1208 from Madhur1997/master
Display `(accepts multiple inputs)` in the help description for Slice flags.
2021-01-28 23:20:42 -05:00
Andrew Nicoll
06e7bdec34 add test for nil 2021-01-27 18:41:52 +00:00
Andrew Nicoll
ebe2c0ea70 add for int64 2020-12-09 12:27:56 +00:00
Andrew Nicoll
02f3866db2 add nother test 2020-12-09 12:26:08 +00:00
Andrew Nicoll
55992853bf add flag tests 2020-12-09 11:59:50 +00:00
Madhur batra
ea14b62ecc Issue #1066: Display (accepts multiple inputs) for SliceFlags in the
help description.
2020-12-01 14:14:15 +05:00
Mostyn Bramley-Moore
500d6b04e6 Report the source of a value when we cannot parse it
If you allow a flag to be set from environment variables or files and
a parse error occurs from one of them, it is very useful for the error
message to mention where the value came from.

Without this, it can be difficult to notice an error caused by an
unexpected environment variable being set.

Implements #1167.
2020-11-03 23:57:00 +01:00
Alex Couture-Beil
2ae03fa69c bugfix: don't overwrite existing stringslice refence
fixes an issue where values set by environment var are not saved to
existing stringslice reference.
2020-08-24 14:20:17 -07:00
Vinicius Schettino
54fbe0a445 Basic test case to check if Value is propagated as it should 2020-07-11 15:55:19 -03:00
Sergey Goroshko
196b222a8b fix #1121(StringSliceFlag set default value into destination) 2020-05-01 23:06:09 +03:00
Mostyn Bramley-Moore
4853dd3144 Reset the environment variables after each test that clears them
Instead of just resetting the temp dir, let's reset all environment
variables.

Environment variables are a pain for testing. A more reliable solution
would be to refactor all functions that read from the environment to
take the environment as an explicit argument, and then provide a
consistent environment during testing. But that would be a significantly
larger change than this one.

Related to #1105.
2020-04-15 08:32:07 +02:00
Mostyn Bramley-Moore
8d907b5329 Save the temp dir before clearing environment variables
In some windows setups, os.TempDir() will return something like
"C:\WINDOWS" if none of the expected environment variables (TMP, TEMP,
USERPROFILE) are set, and then functions that try to create temporary
files or directories will fail since this is not writable.

Several tests in flag_test.go clear the environment and then set a small
number of specific environment variables for the test, triggering the
following error in TestFlagFromFile when I run `go test ./...` on a new
windows machine:

flag_test.go:1667: open C:\WINDOWS\urfave_cli_test851254863: Access is denied.

To work around this, we can check the temp directory before calling
os.Clearenv() and use that directory explcitly in functions that
take the temp directory.

This fixes part of #1105.
2020-04-14 07:55:17 +02:00
davidsbond
e19b1565a8 Allow specifying a StringSlice destination for StringSliceFlag 2020-02-28 12:00:31 +00:00
Dmitry Kutakov
d7e6dde41e
goimports - fix code format 2019-12-30 10:41:15 +01:00
Dmitry Kutakov
94a1912e25
reduce stdout logs in tests
Keep the stdout clean if all tests are passed. It helps to debug a broken test, because only a failed test prints to output.
2019-12-29 17:00:19 +01:00
Martin Lees
d2b7f68cf3 Add more tests 2019-12-12 18:14:08 +01:00