Commit Graph

49 Commits

Author SHA1 Message Date
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
eli 2df767872e fix for counter type rendering as INT (#388)
closes #367
2023-11-13 17:08:13 +11:00
Denis Titusov 9610ed62d9 feat: support multiple env variables (#349) 2023-02-01 06:39:30 +11:00
Alec Thomas 0066abb973 fix: Reset() should always be called before anything else 2022-06-15 20:45:10 +10: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
Mitar deebf0b09b Do not add environment variable to help it is already present.
Fixes #246.
2021-12-05 06:23:18 +11:00
Dilip Somavarapu dd18549686 Update Help.go to make Sub Commands can be Hidden (#207) 2021-09-17 08:21:21 +10:00
Kartikaya Gupta 2d879d2037 Add an option to clamp the help wrap width
This is nice to have because on really wide screens the default
terminal-width wrapping can be a little unpleasant to read.
2021-06-16 23:06:43 +10:00
andrewbaxter b3bdeb18e2 Fixes #125: Support custom per-mapper placeholder text (#169) 2021-05-17 21:31:07 +10:00
Dustin Spicuzza 09467435e1 Add option to not expand subcommand help 2021-03-13 16:41:08 +11:00
Joe Schmitt d48f4e59c3 Add negatable output when using short flag names 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
Julia Ogris 1300b2a3bd options: Add kong.ShortUsageOnError() option
Add kong.ShortUsageOnError() option similar to kong.UsageOnError().
Add tests for UsageOnError and ShortUsageOnError.

Remove the HelpOption summary reset at the beginning of DefaultHelpPrinter:

	 func DefaultHelpPrinter(options HelpOptions, ctx *Context) error {
	-       if ctx.Empty() {
	-               options.Summary = false
	-       }

⚠️ I'm not really sure what the implications of this are, tests still
seem to pass, but maybe this has unintended side effects.
2021-02-16 16:25:07 +11:00
Joe Schmitt f306ae1529 Add aliases to tree help output 2021-02-13 06:37:48 +11:00
Jaco Coetzee 405b2f4fd9 Help Option to position flags in help output
When FlagsLast is set to true, flags are printed after commands.

- Added HelpOptions.FlagsLast bool
- Added test TestFlagsLast
2021-02-09 19:25:17 +11:00
Alec Thomas abbc2dfc2c More group formatting tweaks. 2021-02-09 15:23:05 +11:00
Alec Thomas 294d1d1717 Add a bit of extra spacing if group description is provided.
See #135.
2021-02-09 15:17:29 +11:00
Alec Thomas 7e27c8ecf5 Support a simplified kong.Groups{<key>: <title>} way of specifiying groups.
See #135.
2021-02-09 15:08:22 +11:00
Mickaël Menu b68e1aba63 Add support for groups in the default HelpPrinter (#135) 2021-02-09 06:58:43 +11:00
Rene Zbinden 7b000bd775 Add HelpValueFormatter as discussed in #60 (#61)
Fixes #60 .
2020-02-21 20:24:19 +11:00
Rene Zbinden af533a38fb make HelperOptions CommandTree method exported 2020-02-19 08:39:40 +11:00
Rene Zbinden 4667cdb6e4 change help exit code to 0 2020-02-18 17:35:51 +11:00
Alec Thomas ca3a30c5f1 Make HelpOptions into an Option. 2020-02-02 20:25:13 +11:00
Alec Thomas 0548c6b1af Correctly hide sub-commands. 2019-07-08 14:11:08 +10:00
Alec Thomas 4e9878074f Hide hidden sub-commands. 2019-03-29 11:11:55 +11:00
Alec Thomas 42ea64b1b4 Factor out command help into functions. 2019-01-24 17:14:31 +11:00
Matthias Fax 2a90ca2ad3 feat: add a command tree help view (#32)
Add a command tree help view.

Following up #29 and #30, I noticed that the default help looks quite duplicative since only the help text of the last command in chain is viewed. I needed an option to also show the help text of the command nodes in an appropriate way.  This is what I came up with.
2019-01-22 00:14:26 +11:00
Alec Thomas aedca401da Hide sub-tree when parent is hidden. 2018-11-14 10:01:45 +11:00
Alec Thomas 6fa83bdc0e Apply hooks to default values. 2018-09-20 20:33:55 +10:00
Alec Thomas ebe508cf46 Fix incorrect error missing for missing required args. 2018-08-14 21:05:58 +10:00
Alec Thomas f0bd1294a7 Support detailed help.
Any command/arg implementing the HelpProvider interface will be used to
provide arbitrarily detailed help.
2018-08-14 14:43:55 +10:00
Alec Thomas 27d2a08e53 Use a dynamically sized left column in help. 2018-08-09 20:35:47 +10:00
Alec Thomas 6408010083 Clean up disparity between Context and Kong.
Previously, there was a confusing mix of functionality shared between
the two wherein you would need to use the Kong type for printing errors,
etc. but it did not have access to the context in order to print
context-sensitive usage information. This has been fixed.

Additionally, there are now fuzzy correction suggestions for flags and
commands

Also added a server example which shows how Kong can be used for parsing
in interactive shells. Run with:

    $ go run ./_examples/server/*.go

Then interact with:

    $ ssh -p 6740 127.0.0.1
2018-06-27 09:11:11 +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 d9c0dd25b1 Compact help should display full command. 2018-06-21 00:04:35 +10:00
Alec Thomas 653531d6bc Start making help slightly configurable. 2018-06-20 21:55:39 +10:00
Alec Thomas ecf21e4cc9 Add support for maps. 2018-06-13 22:17:28 +10:00
Alec Thomas c7dca86dad Rename Value.Value to Value.Target to correctly reflect its purpose. 2018-06-13 21:12:56 +10:00
Alec Thomas 96fa9c43d5 Improved documentation and help. 2018-06-05 11:36:51 +10:00
Alec Thomas 2afd4ba47b Help! 2018-06-04 13:55:38 +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
Alec Thomas fdc7230e22 Separate validation into a distinct step.
This allows help to be called even when the parse trace is invalid.
Without this, the command-line would have to be valid in order to use
help at all, which defeats the purpose.
2018-05-31 15:20:45 +10:00
Alec Thomas afbb431641 Convert Hook to an Option. 2018-05-31 15:20:45 +10:00
Alec Thomas cf89213e1e Add hook support. 2018-05-27 18:01:10 +10:00
Alec Thomas d20b44baf4 Remove a bunch of duplicate recover code. 2018-05-26 15:32:45 -04:00
Alec Thomas 0bb304449c Add Trace() function. 2018-05-26 10:04:10 -04:00
Alec Thomas ab5cf7e6ef Tracing parser (#11)
* Add tracing to the parser.

* Synthesize a --help flag.

* Parsing now occurs in multiple phases.

1. Reset target.
2. Parse command-line into a "trace" (no values are written to target).
3. Apply traced, parsed values to the target fields.

This is another step in facilitating context-sensitive help and
completion.

* Detect duplicate flags.
2018-05-22 14:07:43 +10:00
Alec Thomas aea859372c Switch to circleci. 2018-05-19 20:30:04 +10:00
Alec Thomas d03571a873 Use variadic options to configure Kong. 2018-05-18 21:17:48 +10:00