Commit Graph

106 Commits

Author SHA1 Message Date
Alec Thomas 96647c30af feat: add old "passthrough" behaviour back in as an option
`passthrough:""` or `passthrough:"all"` (the default) will pass through
all further arguments including unrecognised flags.

`passthrough:"partial"` will validate flags up until the `--` or the
first positional argument, then pass through all subsequent flags and
arguments.
2024-12-01 20:02:03 +11:00
Alec Thomas 1b9d57eec1 feat: support optionally passing kong.Context to Validate()
Fixes #340
2024-11-03 14:14:55 +11:00
市川恭佑 (ebi) 07c8821614 Fix broken anchor link in README.md (#464) 2024-10-27 07:54:43 +11: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
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
Cole Snodgrass 6c216a37ce fix: typo in README (#451) 2024-08-21 11:55:19 +10:00
Jean-Raphaël Matte 6292953645 docs: specify usage of the placeholder tag (#448) 2024-08-13 13:05:45 +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
Ben Weintraub d315006dca Fix reference to non-existent function in README (#430) 2024-05-29 08:41:28 +10: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
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
Alec Thomas 2af1ea57d6 docs: add list of configuration loaders to README 2023-09-22 20:33:51 +10:00
Artem Klevtsov 1e6f15faac Add EnvFlag util (#378) 2023-09-17 09:39:43 +10:00
Denis Titusov 9610ed62d9 feat: support multiple env variables (#349) 2023-02-01 06:39:30 +11:00
Alec Thomas 919e70103f feat: add filecontent named mapper 2022-11-30 22:27:36 +11:00
Jacob Hochstetler 0c6a9f3a3d Merging issue 280 with master changes (#296) 2022-09-20 05:55:05 -07:00
noisersup 15aa6d8d4e Fix Readme.md 2022-09-17 15:11:48 +10:00
Alec Thomas 0066abb973 fix: Reset() should always be called before anything else 2022-06-15 20:45:10 +10:00
Keilin Olsen 195d56c42e Remove references to flag HelpProviders
As these don't appear to be currently supported, remove references
to them working (from main README)
2022-05-18 01:07:21 -07:00
Keilin Olsen 6042c4b10e Add example of HelpProvider + README
Relocate detailed help docs to main README
2022-05-18 01:07:21 -07:00
Keilin Olsen 1db2ea27af Move old shell/main to subdirectory
Also update README reference to same
2022-05-18 01:07:21 -07:00
pyq-lsa 5538b7f045 change help hook and call Reset later
change to BeforeResolve hook to catch calls to '--help' earlier;
call reset later in Kong.Parse() to allow help hook to get hooked;
add test;
2022-05-03 00:10:19 -07:00
hasheddan 1939f2cda0 Remove extraneous + in README.md
Removes + characters that were included from a previous diff.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2022-02-27 11:14:26 +11:00
leon332157 38c56226ba fix: correct line number for json example (#265) 2022-01-25 07:45:25 +11:00
Mitar a7d3850e80 Cmd can be passthrough now, too.
Fixes #253.
2022-01-05 18:58:37 +11:00
Mitar 88dcc90dde Document nested data structure. 2021-12-25 07:49:21 +11:00
Alec Thomas 9c9b8ab50b More enum fixes. 2021-12-13 18:54:06 +11:00
Alec Thomas c5e464a367 Deprecate HelpFormatter. 2021-12-03 11:48:54 +11:00
Alec Thomas 342263cb51 Fix docs re. Help() interface.
Fixes #241.
2021-11-30 21:39:35 +11:00
Dan 2770a34ce6 Add envprefix tag 2021-10-22 16:25:13 +11:00
Radon Rosborough bf5e5e843d [#88] Use reflect-compatible struct tags in examples (#202)
=
2021-09-15 16:41:30 +10:00
Alec Thomas d1a818b5a1 Allow DynamicCommand to specify arbitrary tags.
Fixes #185.
2021-07-13 13:55:01 +10:00
Cam Hutchison 89315e74ad Allow default commands with cmds/args/flags (#188)
* Move default command validation to build

Move the validation of default commands - checking if a node has
multiple default commands or a default command has children - to the
build phase rather than tracing. These errors are with the structure of
the CLI ast and are detectable before parsing the command line.

Add a couple of tests for some of the default command error cases.

* Disallow positional args on a default command

Do not allow a default command to have positional arguments. The current
check is only for branching args, but the error message implies that
positional args are not allowed either. So add a check for positional
args too, and add a test case for it.

This is breaking change to the API but is unlikely to have ill-effect as
positional args on a default command cannot be used without explicitly
naming the command (i.e. not using it as a default).

* Allow default commands with cmds/args/flags

Allow default commands to have sub-commands, args and flags when tagged
with `default:"withargs"`. This makes specifying the name of the
command on the CLI completely optional as long as the args to that
command are not ambiguous with other commands.
2021-07-12 14:19:37 +10:00
Alec Thomas 247574041d Enum fields must be required or have a default.
This is a breaking change, but the previous behaviour was broken so I'm
not concerned.

Also made most programmer errors more useful by giving type.field
context information.

Fixes #179.
2021-06-21 20:35:41 +09:30
Alec Thomas c494f8b8f3 Support required combined with xor groups.
Fixes #112.
2021-06-21 19:25:54 +09:30
Alec Thomas 54558f65e8 Allow multiple xor:"" groups to be defined.
Fixes #113.
2021-06-21 19:04:54 +09:30
Alec Thomas c4a8cb03a7 Update docs. 2021-06-07 08:56:11 +10:00
Fabian Gutierrez 8d859b918f Add some details to the ignore field example 2021-04-15 06:28:14 +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
Joe Schmitt 454f2c067e Add test case for inverting the negation
Not sure why anyone would do this, but it's covered now.
2021-03-02 10:36:13 +11:00
Joe Schmitt 2fdddc4f51 Add negatable tag to set a bool to be negatable.
If negatable, add `--[no-]` prefix to help.
2021-03-02 10:36:13 +11:00
Mickaël Menu b68e1aba63 Add support for groups in the default HelpPrinter (#135) 2021-02-09 06:58:43 +11:00
Joe Schmitt 2479d83cc0 Add support for command aliases (#130) 2021-01-11 07:36:13 +11:00
Alec Thomas d78d607800 Fully describe how help is generated.
See #29.
2020-12-06 14:59:38 +11:00
Alec Thomas 73064c7b8f Fix README again. 2020-10-21 20:26:16 +11:00
Alec Thomas 74d8f6d21b Unbreak README. 2020-10-21 19:38:05 +11:00
Alec Thomas 38db823367 Call Validate() functions on nodes if present. 2020-10-21 19:14:31 +11:00