51 Commits

Author SHA1 Message Date
S.Solodyagin 575a0cdf6e Merge remote-tracking branch 'upstream/master' 2025-07-02 20:54:46 +03:00
Sam Xie 66d5762b66 Support parsing integer literals (#529) 2025-04-24 08:24:47 +10:00
Abhinav Gupta 9f71a49767 ci: Test with Go 1.23 and 1.24 (#502)
In CI, test with Go 1.23 and 1.24,
and upgrade the Hermit-managed Go and golangci-lint to latest versions.

The new golangci-lint had a number of warnings and minor issues
that were either fixed or opted-out of.
2025-02-17 14:10:57 +11:00
Alec Thomas cab639ab83 chore: add test for decoding 2025-02-13 11:22:03 -08:00
s.solodyagin 6795fa089a rename 2024-04-03 20:59:37 +03:00
Alec Thomas a41b2e8f4e fix: slices/maps of existingfile would fail to work 2024-03-08 17:20:45 +11:00
Alec Thomas 8e675d6130 fix: broken test 2024-03-06 09:45:31 +11:00
Chris Stephen 4a9fe056ea Support string pointers for path mapper (#360) 2024-03-05 19:59:11 +11:00
Abhinav Gupta 7391017a8c Drop references to io/ioutil (#403)
io/ioutil has been deprecated for a while.
Replace all uses of it with equivalent APIs.
2023-12-11 10:40:40 +11:00
Abhinav Gupta a86bda490b golangci-lint: Upgrade, fix issues (#397)
The golangci-lint being used was quite dated.
This change upgrades to the latest version.
Adds and updates exclusions based on new failures.

Note on revive:
I've included an opt-out for unused parameters for revive
because turning `newThing(required bool)` to `newThing(_ bool)`
is a loss of useful information.

The changes to the Go files are to fix the following issues:

```
camelcase.go:16: File is not `gofmt`-ed with `-s` (gofmt)
config_test.go:50:18: directive `//nolint: gosec` is unused for linter "gosec" (nolintlint)
defaults_test.go:28:25: G601: Implicit memory aliasing in for loop. (gosec)
doc.go:5: File is not `gofmt`-ed with `-s` (gofmt)
kong.go:446:18: directive `//nolint: gosec` is unused for linter "gosec" (nolintlint)
kong_test.go:503:20: G601: Implicit memory aliasing in for loop. (gosec)
model.go:493:10: composites: reflect.ValueError struct literal uses unkeyed fields (govet)
scanner.go:112: File is not `gofmt`-ed with `-s` (gofmt)
```

And to address broken nolint directives reported as follows by
golangci-lint.

```
[.. skipped .. ]
tag.go:65:1: directive `// nolint:gocyclo` should be written without leading space as `//nolint:gocyclo` (nolintlint)
tag.go:206:51: directive `// nolint: gocyclo` should be written without leading space as `//nolint: gocyclo` (nolintlint)
util_test.go:23:43: directive `// nolint: errcheck` should be written without leading space as `//nolint: errcheck` (nolintlint)
util_test.go:51:22: directive `// nolint: errcheck` should be written without leading space as `//nolint: errcheck` (nolintlint)
```
2023-12-11 09:37:07 +11:00
Abhinav Gupta 3263463a7e Fix Windows tests, verify in CI (#394)
* ci: Test on Windows too

Adds a Windows test run to CI.
Go setup relies on GHA for this
because Hermit doesn't yet support Windows.

* fix(mapper_windows_test): assert.NotNil => assert.True

assert.NotNil does not exist.

* filecontent mapper: Handle error from directory

If we couldn't read because the source is a directory,
override the original error message.

* fix(test): Handle platform-specific "file not found" messages
2023-12-10 15:42:50 +11:00
Alec Thomas 919e70103f feat: add filecontent named mapper 2022-11-30 22:27:36 +11:00
Jan Heuermann 32e8ffc6fd Fix large number processing for unsigned types 2022-10-18 08:54:38 +11:00
Sever Băneșiu c62bf25854 Fix loading large integers from JSON files (#334) 2022-09-22 10:10:58 +10:00
pyqlsa a05a0c20ba Add Active member to Nodes and Values (#319) 2022-07-19 22:43:15 -07:00
Alec Thomas e75e1ca88a refactor: switch to alecthomas/assert 2022-06-21 20:58:10 +10:00
pyq-lsa 0aaa4c1199 fix: existing file/dir always checks default
updated existing file/dir mappers to early return if already set;
added tests for existing file/dir mappers;
2022-05-16 15:37:38 -07:00
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