Commit Graph

400 Commits

Author SHA1 Message Date
renovate[bot] c90c6732cc chore(deps): update module github.com/alecthomas/kong to v1.3.0 (#467) 2024-11-04 13:51:07 +11:00
Alec Thomas 2544d3f008 feat: add AfterRun() hook
Fixes #288
2024-11-03 14:49:27 +11:00
Alec Thomas d0beaf7df3 fix: update enum+default vars after interpolation
This doesn't recursively apply interpolation, as discussed in the issue,
but that's a much bigger change.

Fixes #337
2024-11-03 14:28:27 +11:00
Alec Thomas 1b9d57eec1 feat: support optionally passing kong.Context to Validate()
Fixes #340
2024-11-03 14:14:55 +11:00
Alec Thomas 64229c9fe7 fix: format enum value
Fixed in #415
2024-11-03 14:02:03 +11:00
Alec Thomas 7bbb0b76ad feat: support recursive injection of provider parameters
This allows provider functions to accept parameters that are injected by other
bindings or binding providers, eg. call the provider function with the root CLI
struct (which is automatically bound by Kong):

  kong.BindToProvider(func(cli *CLI) (*Injected, error) { ... })
2024-11-01 12:25:41 +11:00
Alec Thomas 373692af87 refactor: reuse callAnyFunction for callFunction
Rather than duplicating basically identical calling logic
2024-11-01 11:59:18 +11:00
市川恭佑 (ebi) 07c8821614 Fix broken anchor link in README.md (#464) 2024-10-27 07:54:43 +11:00
renovate[bot] 56e990fc15 chore(deps): update all non-major dependencies (#462)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-10-07 14:25:31 +11:00
renovate[bot] c9fbc305f4 chore(deps): update module github.com/alecthomas/assert/v2 to v2.11.0 (#459)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-09-23 10:05:14 +10:00
Alexey Palazhchenko b34e9952de Fix Markdown in README.md (#458) 2024-09-19 18:27:07 +10:00
Alec Thomas 31301f527c docs: add note about 1.0 to README 2024-09-19 04:10:05 +10:00
renovate[bot] 3b28c2c83a chore(deps): update module github.com/alecthomas/kong to v1 (#457)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-09-16 19:49:21 +10:00
Alec Thomas 26c1c9ad05 fix: allow duplicate custom negated flags
Fixes #456
2024-09-12 12:05:09 +10:00
Bob Lail 9924ec4461 fix!: Include -- in passthrough args (#436)
Given a grammar like this:

```golang
var cli struct {
        Args []string `arg:"" optional:"" passthrough:""`
}
```

If Kong parses `cli foo -- bar`, it will populate `Args` with `[]string{"foo", "--", "bar"}` (including "`--`").
However, if Kong parses `cli -- foo bar`, will populate `Args` with `[]string{"foo", "bar"}` (leaving off `"--"`).

This differs from the behavior of a passthrough Command, where `"--"` is included with the args in both cases.

There are 3 places where `c.endParsing()` is called
1. When `node.Passthrough` is true: https://github.com/alecthomas/kong/blob/5f9c5cc822bdb888a3671c44d4688a6f602ecb90/context.go#L366-L368
2. When `arg.Passthrough` is true: https://github.com/alecthomas/kong/blob/5f9c5cc822bdb888a3671c44d4688a6f602ecb90/context.go#L451-L453
3. When `"--"` is encountered: https://github.com/alecthomas/kong/blob/5f9c5cc822bdb888a3671c44d4688a6f602ecb90/context.go#L384-L387

The first two do not also pop any tokens. The third one does.

This commit makes `c.scan.Pop()` conditional, skipping it when the next positional argument is passthrough.

I believe this will cause Kong to behave a little more consistently — and from my perspective, `--` is relevant for args intended to be passed through! — but it will change the behavior of existing projects that use `arg:"" passthrough:""`.
2024-09-11 10:51:37 +10:00
Cam Hutchison 4ecb53599b Make negatable flag name customisable (#439)
* fix: Check if negatable duplicates another flag

Add a check for flags with the `negatable` option if the negative flag
conflicts with another tag, such as:

    Flag   bool `negatable:""`
    NoFlag bool

The flag `--no-flag` is ambiguous in this scenario.

* feat: Make negatable flag name customisable

Allow a value on the `negatable` tag to specify a flag name to use for
negation instead of using `--no-<flag-name>` as the flag.

e.g.

    Approve bool `default:"true",negatable:"deny"`

This example will allow `--deny` to set the `Approve` field to false.
2024-09-10 21:02:37 +10:00
Camilla 7d84b95294 Feature: Add check for overlapping xor and and groups (#443)
* Docs: Clean and group description

* Feat: Add check for overlapping xor and and groups

Co-authored-by: inful <jone.marius@vign.es>

* Chore: Rewrite overlap err to avoid duplicated words

---------

Co-authored-by: inful <jone.marius@vign.es>
2024-09-10 21:01:12 +10:00
renovate[bot] b297ae97f2 chore(deps): update all non-major dependencies (#455)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-09-10 21:00:16 +10:00
Cole Snodgrass 6c216a37ce fix: typo in README (#451) 2024-08-21 11:55:19 +10:00
Alec Thomas 2ad9498bdf chore: bump go + golangci-lint 2024-08-20 08:16:24 +10:00
Jean-Raphaël Matte 6292953645 docs: specify usage of the placeholder tag (#448) 2024-08-13 13:05:45 +10:00
renovate[bot] d113f61e2a chore(deps): update all non-major dependencies (#445)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-08-12 16:24:10 +10:00
Camilla ff6d5ba7d5 Feature: Add xand tag (#442)
* Feat: Add xand group and check for missing

* Fix: Split and combine err in TestMultiand for consistency

* Feat: Check missing required flags in xand groups

* Feat: Handle combined xor and xand

* Docs: Add info about combined xand and required use

* Docs: Fix language error in xand description

Co-authored-by: Stautis <thkrst@gmail.com>

* Feat: Rename xand to and

* Refactor: Switch from fmt.Sprintf to err.Error

* Refactor: Get requiredAndGroup map in separate function

---------

Co-authored-by: Stautis <thkrst@gmail.com>
2024-08-08 16:58:22 +10:00
Mitar 5f9c5cc822 Remove extra newline when message contains trailing newlines. (#387) 2024-07-05 22:52:45 +10:00
Leo Antunes e864bb0220 feat: allow non-structs to be used as commands (#428)
* feat: allow non-structs to be used as commands

This small MR allows using the func-to-interface trick to implement a command (see commandFunc in kong_test.go).

This is useful e.g. for commands that have no flags or arguments of their own, but instead receive all required information via bound  parameters.

* fix: check DynamicCommand is runnable when adding
2024-07-05 22:51:38 +10:00
renovate[bot] 605cdd64a9 chore(deps): update all non-major dependencies (#425)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-07-05 22:49:21 +10:00
Bob Lail fcb5e05c07 fix: When a Grammar combines flags with passthrough args, see if an unrecognized flag may be treated as a positional argument (#435)
* ci: Add a test for positional args that are passthrough on a command that isn't passthrough

* fix: When a Grammar combines flags with passthrough args, see if an unrecognized flag may be treated as a positional argument

Given a grammar like this:
```golang
var cli struct {
	Args []string `arg:"" optional:"" passthrough:""`
}
```

The first positional argument implies that it was preceded by `--`, so subsequent flags are not parsed.

If Kong parses `cli 1 --unknown 3`, it will populate `Args` with `[]string{"1", "--unknown", "3"}`.
However, if Kong parses `cli --unknown 2 3`, it will fail saying that `--unknown` is an unrecognized flag.

This commit changes the parser so that if an unknown flag _could_ be treated as the first passthrough argument, it is.

After this change, if Kong parses `cli --unknown 2 3`, it will populate `Args` with `[]string{"--unknown", "2", "3"}`.

* ci: Skip the `maintidx` linter for `trace()`
2024-07-05 22:48:33 +10:00
Ben Weintraub d315006dca Fix reference to non-existent function in README (#430) 2024-05-29 08:41:28 +10:00
Alex Broad 38e5c6198e Update help example to use vars (#429) 2024-05-27 21:02:24 +10:00
renovate[bot] 2ab5733f11 chore(deps): update all non-major dependencies (#424)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-10 23:12:03 +10:00
renovate[bot] 0376ce4e06 chore(deps): update module github.com/gliderlabs/ssh to v0.3.7 (#421)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-03-25 17:45:36 +11:00
Adam Lesperance 958a344920 Aliases can be duplicated between different sub commands (#419)
Make sure we remove all the aliases from the seenFlags tracker just like we do with other flags/short flags
2024-03-15 06:17:27 +11:00
renovate[bot] 3f756c1dbd chore(deps): update all non-major dependencies (#418)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-03-11 12:37:34 +11: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
renovate[bot] 088cd7874e chore(deps): update all non-major dependencies (#410)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-03-05 10:53:35 +11:00
Alec Thomas 51e3de86cf chore(renovate): disable golangci-lint 2024-03-05 10:13:52 +11:00
Dennis Ploeger dc13080e39 feat: Add info about optional flags to usage (#416) 2024-02-27 19:39:21 +11:00
Prashant Varanasi fa9b636997 Support aliases for flags (#409)
Aliases are currently only supported for sub-commands, but they're
useful for flags as well. E.g., when migrating from an old flag name
to a new flag name, while still supporting the old value.
2024-02-27 11:10:15 +11:00
renovate[bot] 30e84613fe chore(deps): update module github.com/alecthomas/assert/v2 to v2.5.0 (#407)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-01-22 19:21:44 +11:00
renovate[bot] 5e5a0cf53d chore(deps): update all non-major dependencies (#406)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-01-15 14:47:48 +11:00
renovate[bot] 4907efc9c8 chore(deps): update all non-major dependencies (#405) 2023-12-25 13:33:17 +11:00
Abhinav Gupta de00f3b71c ci: Test against Go 1.20 and 1.21 (#404)
Per the [Go Release Policy][1], upstream supports
only the two most recent major releases of Go.
For example, with Go 1.21 available, only 1.21 and 1.20 are supported.
Many projects adopt a similar support policy
to strike a balance between new features and backwards support.

  [1]: https://go.dev/doc/devel/release#policy

If the project has the same policy,
it makes sense to test against both versions of Go.

This change adds a test matrix to CI,
testing against both Go 1.20 and 1.21,
on both Windows and Linux.
2023-12-11 11:03:29 +11:00
renovate[bot] 6997afd4f9 chore(deps): update actions/setup-go action to v5 (#400)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-11 10:42:05 +11:00
renovate[bot] 27806be88f chore(deps): update actions/checkout action to v4 (#399)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-11 10:41:53 +11:00
renovate[bot] d63c4d71e9 chore(deps): update module github.com/chzyer/readline to v1 (#401)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-11 10:41:39 +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 923c202213 hermit: Add back Go package (#402)
PR #398 looks like it deleted the Go package
so CI will revert to whatever is installed on GitHub runners by default.

Add back the Go package.
2023-12-11 10:31:04 +11:00
renovate[bot] 79809cbb47 chore(deps): update all non-major dependencies (#398)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-11 09:39:58 +11:00