Commit Graph

273 Commits

Author SHA1 Message Date
Dilip Somavarapu dd18549686 Update Help.go to make Sub Commands can be Hidden (#207) 2021-09-17 08:21:21 +10:00
Radon Rosborough bf5e5e843d [#88] Use reflect-compatible struct tags in examples (#202)
=
2021-09-15 16:41:30 +10:00
Stan Rozenraukh 74cb5130e3 Adds Context.BindToProvider (#201) 2021-08-31 06:47:02 +10:00
Alec Thomas d0c0180cec Hydrate pointers to embedded structs. 2021-08-28 16:54:55 +10:00
Daniel Selans 07faa2e0d0 Add ability to ignore fields that match given regex pattern(s) (#199) 2021-08-28 15:41:08 +10:00
Alec Thomas dd904ce961 Upgrade golangci-lint. 2021-08-27 20:58:22 +10:00
Alec Thomas 43616c6a6d Hydrate sub-commands that are pointers.
Fixes #196.
2021-08-27 20:57:38 +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
Simon Frei 5a9c9c7864 Bubble errors instead of panicking (#194) 2021-08-19 18:00:53 +10:00
Nikita Semikov f547618963 Add aliases to ALL help output (#191) 2021-08-07 22:04:51 +10:00
Alec Thomas 676890f22f Switch to GHA. 2021-08-01 14:45:09 +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 cfbe844aa4 Fix xor + required combo.
See #112.
2021-07-11 21:23:18 +10:00
Evgeny 8b2821cc24 Added sub objects support in JSON resolver (#178) 2021-06-21 21:08:43 +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 8aa52739ea Don't fail on required positional arguments that have envars.
Fixes #153.
Fixes #120.
2021-06-21 17:13:39 +09:30
Evgeny a8244400e3 DefaultEnvars option (#177) 2021-06-20 20:27:56 +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
Alec Thomas 33ce628ecd Hermitise CI. 2021-06-09 13:13:50 +10:00
Alec Thomas 8cbf5a6c03 Validate short flags are a single rune.
Fixes #175.
2021-06-09 13:11:49 +10:00
Alec Thomas ff93d67a8d Validate duplicate short flags.
Fixes #174.
2021-06-09 13:01:16 +10:00
Alec Thomas 6cebaa7b85 Hermitise and bump golangci-lint. 2021-06-09 12:48:47 +10:00
Alec Thomas c4a8cb03a7 Update docs. 2021-06-07 08:56:11 +10:00
Mary Fesenko 1f5bbd5559 Fix issue with negatable flag being negated twice (#171) 2021-05-22 21:50:50 +10:00
andrewbaxter b3bdeb18e2 Fixes #125: Support custom per-mapper placeholder text (#169) 2021-05-17 21:31:07 +10:00
Toshimaru 9c81441ae0 Update go modules (#165) 2021-05-03 14:16:08 +10:00
Alec Thomas 2e611623a7 Don't display placeholder for counters.
Fixes #164.
2021-04-18 10:05:26 +10:00
Fabian Gutierrez 8d859b918f Add some details to the ignore field example 2021-04-15 06:28:14 +10:00
Rene Zbinden 5fd7249c69 fix panic resolver's configuration file does not have read permission 2021-04-14 19:39:32 +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
Alec Thomas 49417fe966 Add support for dynamically registered commands. 2021-04-02 11:38:24 +11: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
Alec Thomas 0c83d0f8dc Lint fix. 2021-03-13 21:13:23 +11:00
Alec Thomas 93f73cf38c Display multiple optional args in a more expected way.
Previously:

    Usage: command [<one>] [<two>]

Now:

    Usage: command [<one> [<two>]]

Thanks to @juliaogris for the inspiration!
2021-03-13 20:30:28 +11:00
Dustin Spicuzza 09467435e1 Add option to not expand subcommand help 2021-03-13 16:41:08 +11:00
Andrew Haines 456575db97 Allow - for stdout in path mapper (#147) 2021-03-02 16:26:10 +11:00
Joe Schmitt d48f4e59c3 Add negatable output when using short flag names 2021-03-02 10:36:13 +11:00
Joe Schmitt ed24960916 Implement code review feedback 2021-03-02 10:36:13 +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
Joe Schmitt 2a0d7af9c5 Add support for negated boolean flags
Will automatically set a boolean Struct field to false if the flag starts with `--no-`, even when the default is `true`.

For example:
```
type Cmd struct {
  Output bool `default:"true"`
}
```

Calling
```
command
```
Will set `Output` to `true`, but
```
command --no-output
```
Will set `Output` to `false`.
2021-03-02 10:36:13 +11:00
Alec Thomas 541ee3302f Create FUNDING.yml 2021-03-01 16:59:26 +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