63 Commits

Author SHA1 Message Date
Sam Xie 66d5762b66 Support parsing integer literals (#529) 2025-04-24 08:24:47 +10:00
Alec Thomas a32b94b705 chore: interface{} -> any 2024-12-29 08:10:34 +09:00
Alec Thomas a41b2e8f4e fix: slices/maps of existingfile would fail to work 2024-03-08 17:20:45 +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 46c03841ed fix: support IsBool() on MapperValue implementations.
Fixes #381
2023-09-30 16:11:22 +08:00
Alec Thomas 919e70103f feat: add filecontent named mapper 2022-11-30 22:27:36 +11:00
Alec Thomas 9b08b89396 fix: ensure pointers can be detected as bools
This required adding a BoolMapperExt interface.
2022-11-26 11:21:39 +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
Jacob Hochstetler 0c6a9f3a3d Merging issue 280 with master changes (#296) 2022-09-20 05:55:05 -07: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 edc47ebc34 helpful error message when flag is missing values (#310)
Fixes #277
2022-06-11 14:29:19 -07: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
Denis Titusov 89b2806f6a Switch to the standard errors API, that was introduced in 1.13 (#273)
* Switch to the standard errors API, that was introduced in 1.13

* Fix linter errors 🤦‍

* Remove withStackError

* fix: freeze go version to 1.17, since 1.18 introduced generics, which are not supported by linters yet

* fix: freeze go version to 1.17, since 1.18 introduced generics, which are not supported by linters yet
2022-03-18 18:54:29 +11: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
Alec Thomas 6cebaa7b85 Hermitise and bump golangci-lint. 2021-06-09 12:48:47 +10:00
andrewbaxter b3bdeb18e2 Fixes #125: Support custom per-mapper placeholder text (#169) 2021-05-17 21:31:07 +10:00
Saj Goonatilleke 57bfb058d5 mapper: correct text/binary typo
Fixes a panic when attempting to make use of pointers to types that
implement encoding.BinaryUnmarshaler.  e.g.:

    type SomeBinaryFlag struct{}

    func (f *SomeBinaryFlag) UnmarshalBinary(data []byte) error {
	    // ...
	    return nil
    }

    var cli struct {
	    Binary *SomeBinaryFlag
    }
2021-03-18 06:11:20 +11: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 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
Muhammad Talal Anwar f410bb770f Fix typo 2020-07-27 07:15:02 +10:00
Alec Thomas e10381694b Allow unsetting of FileContentFlag values. 2020-07-10 13:52:32 +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 b6ff115b3e Correctly parse all numeric types.
Fixes #76.
2020-04-29 09:09:28 +10:00
Alec Thomas 51a1ea979a Ensure "existingfile" doesn't choke on "-". 2020-04-27 09:10:44 +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 cd3f64f045 Support "yes", "1" and "true" for bool values. 2019-11-13 08:20:41 +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 2ac3d43124 Make invalid value error messages more useful. 2019-04-01 10:07:10 +11:00
Alec Thomas 072357f8ba Make ExpandPath public. 2018-11-06 11:37:26 +11:00
Alec Thomas 041e879d63 Expand ~ for FileContentFlag. 2018-11-03 09:51:57 +11:00
Alec Thomas c0df056b14 Simplify FileContentFlag. 2018-10-25 12:53:55 -07:00
Alec Thomas d648254c7d Don't blindly SetString. 2018-09-22 21:18:22 +10: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 844494faff Allow bool flags to be set to true or false explicitly. 2018-09-11 23:57:18 +10:00
Alec Thomas 856d62e28a Support multiple key+value pairs for map flags. 2018-07-26 20:35:20 +10:00