Commit Graph

34 Commits

Author SHA1 Message Date
David Shiflet 29685e7da6 treat \ as escape only before a separator 2022-05-16 13:03:54 -07:00
Alec Thomas 7c6ff10d33 fix: values that look like flags would not be parsed correctly
Specifically, when parsing into slices or maps.

Fixes #290
2022-04-08 06:43:08 +10:00
Alec Thomas 1d48b6f720 Allow Mappers to contribute Vars to interpolation.
See #218.
2021-09-27 16:07:48 +10:00
Yunchi Luo b5bcf3579b Support duration as nanosecond number when using a resolver
Duration is always marshaled as a nanosecond number when using JSON. Kong would only parse it as a string using ParseDuration. Now it can use the number version too.
2021-08-27 04:31:39 +10:00
andrewbaxter b3bdeb18e2 Fixes #125: Support custom per-mapper placeholder text (#169) 2021-05-17 21:31:07 +10:00
Franklin "Snaipe" Mathieu d4dd709445 tag: add passthrough for positional arguments
This new tag tells the parser to stop processing flags after the
positional argument is encountered.

This is particularly useful for subcommands that forward their arguments
to an external program, and makes it possible to implement commands
like `kubectl exec` or `docker run`.

Fixes #80.
2021-04-06 07:53:16 +10:00
Andrew Haines 456575db97 Allow - for stdout in path mapper (#147) 2021-03-02 16:26:10 +11:00
Alec Thomas 3d57e73d11 Ensure values aren't nil before decoding. 2020-12-04 16:20:06 +11:00
Alec Thomas 26524e0cc1 Actually test filename. 2020-10-30 15:36:16 +11:00
Alec Thomas 8bf0a335db Add NamedFileContentFlag. 2020-10-30 15:26:38 +11:00
Alec Thomas 88ecc9c4e9 Fix enum's from envars not validating (fixes #107).
Also added a mapper for `*os.File`.
2020-09-08 13:46:23 +10:00
Alec Thomas d480572d75 Make counter flags more flexible.
They now support three forms:

    -s
    --long
    --long=N

The last of which explicitly sets the counter value.

Fixes #87.
2020-06-10 15:40:22 +10:00
Cam Hutchison b89354adb0 Fix sep:"none" and mapsep:"none"
According to the README.md, a value of `"none"` for the `sep` tag (for
slices) and `mapsep` (for maps) is meant to disable the separator that
would allow multiple entries to be added from a single argument.
However, using `"none"` just set the separator to the rune `'n'`.

Fix the parsing of the tag, and also update `SplitEscaped` to not split
with a separator of `-1`.

Add a new test for the new cases.
2020-06-02 17:19:11 +10:00
Alec Thomas 2d809c073b Fix integer overlows in tests on 32-bit systems.
Fixes #77.
2020-04-30 19:48:20 +10:00
Alec Thomas b6ff115b3e Correctly parse all numeric types.
Fixes #76.
2020-04-29 09:09:28 +10:00
Alec Thomas c45ea59559 Add type:"counter".
Useful for eg. "-vvv" incrementing verbosity.

Fixes #65.
2020-03-01 14:35:56 +11:00
Rene Zbinden 529703d8d1 add support to make map separator configurable 2020-02-14 21:25:58 +11:00
Alec Thomas b4ae5fb86e Correctly support encoding.{TextUnmarshaler,BinaryUnmarsheler} 2020-02-01 18:21:06 +11:00
Alec Thomas 01b720cb19 Test and docs for TextUnmarshaler and json.Unmarshaler. 2020-01-10 12:15:54 +11:00
Alec Thomas 1076f5ee1f Remove unused return value from PopValueInto. 2019-06-21 10:07:24 +10:00
Alec Thomas 439c674f7a Use interface{} instead of string in tokens.
This allows the scanner and resolvers to pass Go types around rather
than having to serialise/deserialise to/from strings.
2019-04-24 23:25:13 +10:00
Alec Thomas e474873f84 Don't show ... in help for named slice types. 2018-11-06 11:15:35 +11:00
Alec Thomas c0df056b14 Simplify FileContentFlag. 2018-10-25 12:53:55 -07:00
Alec Thomas 0f67a38060 Make FileContentFlag a struct to keep track of the path. 2018-09-22 17:09:28 +10:00
Alec Thomas 1048bd0448 Add a FileContentFlag that loads the contents of a file into a flag
value.
2018-09-22 11:14:14 +10:00
Alec Thomas 856d62e28a Support multiple key+value pairs for map flags. 2018-07-26 20:35:20 +10:00
Alec Thomas b2cab08684 Add support for a mapper interface directly on fields.
If a field implements the MapperValue interface that interface will be
used.
2018-06-29 12:33:50 +10:00
Alec Thomas 00847157a1 Ensure -- consumes all tokens, not just positional. 2018-06-23 08:13:34 +10:00
Alec Thomas a2ec050947 Implement a robust Context.Run().
This helps when composing large applications from separate command
structs.
2018-06-21 21:50:30 +10:00
Alec Thomas e4f37b5d1a Support url.URL. 2018-06-21 16:47:53 +10:00
Alec Thomas 212ea2a356 Add path, existingfile and existingdir types.
- Document custom types.
- Add docker example.
2018-06-21 16:19:08 +10:00
Alec Thomas e9d88d6528 Implement flag "resolvers". (#24)
* Propagate errors.
* Use junit test output.
* Expand role of DecodeContext to include Scanner.
* Inject resolved flags as Path elements in the Context.
  This allows all existing logic to apply seamlessly: hooks, required
flags, etc.
* Clarify that hooks can be called multiple times.
2018-06-12 07:20:55 +10:00
Alec Thomas 96fa9c43d5 Improved documentation and help. 2018-06-05 11:36:51 +10:00
Alec Thomas 48af58cefa Decoders are now field mappers.
Mappers are responsible for mapping from command-line input to Go. This
is typically just decoding, but also includes other information such as
if the field is a bool.
2018-06-04 13:13:09 +10:00