Commit Graph

216 Commits

Author SHA1 Message Date
Alec Thomas 8bf0a335db Add NamedFileContentFlag. 2020-10-30 15:26:38 +11:00
Alec Thomas 097bba54ec Revert UsageOnMissing.
This was breaking UsageOnMissing() when combined with validation of
positional arguments, in that it was allowing positional arguments to be
omitted. It also broke UsageOnMissing() somehow so that it did not work.
2020-10-27 17:33:46 +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
hasheddan a062611ecf Do not run parent node on missing child err with usageOnMissing option
Refactors usageOnMissing option to not run parent commands after
printing usage when a child node is missing.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-10-20 09:44:46 +11:00
Sven Nebel 5b3fd5476a Refactor k.FatalIfErrorf to use k.Fatalf 2020-10-11 07:44:14 +11:00
hasheddan 5cf89d77b1 Fix minor typo in README
Corrects mapperss to mappers.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-10-08 12:29:02 +11:00
Alec Thomas 259d19076d Add support for plugins. 2020-09-16 16:41:18 +10:00
Alec Thomas 067f0e835f More useful error message when finding an unexpected struct. 2020-09-12 16:32:10 +10:00
hasheddan d1821a0666 Add UsageOnMissing option to Kong
Adds an UsageOnMissing option which configures Kong to omit errors and
display usage when a command is invalid due to a missing argument. This
can be useful if a user wishes for the top-level command to print usage
when no args are supplied, or if they would prefer child commands which
have their own subcommands to print usage specific to that command.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-09-11 17:10:18 -07: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
Alex Snast cbae65d227 Make PostBuild global. 2020-08-23 23:48:18 -07:00
Muhammad Talal Anwar f410bb770f Fix typo 2020-07-27 07:15:02 +10:00
Alec Thomas 055081422d When using resolvers, use last value only.
This fixes an issue where the value and all its hooks would
be applied for each resolver, making it difficult to compose multiple
config files.
2020-07-10 16:37:03 +10:00
Alec Thomas e10381694b Allow unsetting of FileContentFlag values. 2020-07-10 13:52:32 +10:00
Alec Thomas 047801d760 Correctly return errors when configuration parsing fails.
Fixes #93.
2020-07-08 21:12:29 +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 d4822839a2 Add GetSep to simplify Tag initialisation
Factor out some repetition from `parseTag()` into a `GetSep()` method so
as to simplify `parseTag()` and formalise the semantics of a separator.

The existing behaviour in corner/error cases has been preserved, but an
appropriate error is returned (currently ignored) so a future breaking
change could be made to handle these conditions.

Tests have not been added as the test files are in a separate package to
the unit under test, making direct `Tag` construction difficult. Testing
through the exported APIs is already performed in the
`FormatPlaceHolder()` tests.
2020-06-02 17:19:11 +10:00
Cam Hutchison f19f1031c0 Format help placeholders with slice/map separators
Use the specified separators for a flag in the placeholders printed in
the help message for slices and maps. Do not print the separator and
ellipsis if the separator is disabled (`"none"`).

Previously the default separator was printed with an ellipsis, ignoring
the `sep` and `mapsep` tags.

Add tests for `Flag.FormatPlaceHolder()`.
2020-06-02 17:19:11 +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
Cam Hutchison b11ebc500b Fix help tests with the introduction of -h
Commit c77deac080 in PR #83 added `h` as
the short flag for help, but the help tests were not updated. Update the
tests with the `-h` in the help output.
2020-06-01 22:25:13 +10:00
Dima Kotik c77deac080 Added -h as default short parameter for the automatic --help flag. 2020-06-01 21:22:47 +10:00
Will Roden 7bdb319cf1 move CloneWith() call into interpolate() 2020-05-16 09:35:03 +10:00
Will Roden f19cb8c69d factor CloneWith out of most interpolate cases 2020-05-16 09:35:03 +10:00
Will Roden 1ccbbb9db4 add benchmark 2020-05-16 09:35:03 +10:00
Alec Thomas c690640e71 Format file. 2020-05-05 12:13:58 +10:00
Freestate17 c69b9a1e88 added post-build option (#78)
* added post-build option

* updated PostBuild function description

Co-authored-by: Daniel Lins <daniel.lins@vidoori.com>
2020-05-05 08:14:33 +10:00
Alec Thomas 2d809c073b Fix integer overlows in tests on 32-bit systems.
Fixes #77.
2020-04-30 19:48:20 +10:00
Alec Thomas ed7caf6841 Revert "Convert env management to a resolver."
This reverts commit fbe8d48e4b.
2020-04-30 17:03:21 +10:00
Alec Thomas b6ff115b3e Correctly parse all numeric types.
Fixes #76.
2020-04-29 09:09:28 +10:00
Alec Thomas d69514dd55 Update README with note about existingfile and -. 2020-04-27 09:13:11 +10:00
Alec Thomas 51a1ea979a Ensure "existingfile" doesn't choke on "-". 2020-04-27 09:10:44 +10:00
Alec Thomas 407c8229a6 Allow "-" as a positional or flag argument.
See #70.

There are some more elaborate ideas in that issue, but I think this is
sufficient for now.
2020-04-27 09:08:33 +10:00
Alec Thomas 860aaac388 Allow Run() on arbitrary nodes.
This is useful for dynamically running commands.
2020-04-26 19:01:43 +10:00
Alec Thomas fbe8d48e4b Convert env management to a resolver.
This ensures that hooks correctly detect when values are set via
environment variables. Fixes #73.
2020-04-16 22:20:43 +10:00
Ryan Hall a77a484f6a Add doc for "-" tag 2020-04-08 09:05:56 +10:00
Alec Thomas 109dce7ea5 Expand variables in config paths. 2020-03-05 11:27:53 +11:00
Alec Thomas b8c82fea7c Allow binds to be provided by a function.
This is useful for situations where the initialisation of some object
should be deferred, eg. when there are distinct "setup" and "use" phases
to a tools lifecycle.
2020-03-03 14:07:40 +11: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 7b000bd775 Add HelpValueFormatter as discussed in #60 (#61)
Fixes #60 .
2020-02-21 20:24:19 +11:00
Alec Thomas 73ecfde9b2 Automatically add envar to help.
See #57.
2020-02-19 15:52:02 +11:00
Alec Thomas b21bf1031a Support interpolating "$env".
Fixes #57.
2020-02-19 13:27:12 +11:00
Rene Zbinden af533a38fb make HelperOptions CommandTree method exported 2020-02-19 08:39:40 +11:00
Alec Thomas ada7d7bf11 Fix panic when "-" is not followed by a short flag. 2020-02-18 19:54:09 +11:00
Rene Zbinden 4667cdb6e4 change help exit code to 0 2020-02-18 17:35:51 +11:00
Rene Zbinden 529703d8d1 add support to make map separator configurable 2020-02-14 21:25:58 +11:00
Alec Thomas ca3a30c5f1 Make HelpOptions into an Option. 2020-02-02 20:25:13 +11:00
Alec Thomas b4ae5fb86e Correctly support encoding.{TextUnmarshaler,BinaryUnmarsheler} 2020-02-01 18:21:06 +11:00
Alec Thomas 60222fe397 Add README + go modules to server example. 2020-01-24 20:02:10 +11:00