Commit Graph

121 Commits

Author SHA1 Message Date
Lynn Cyrin
f4128a02f3
Update command.go 2019-08-01 22:54:15 -07:00
Lynn Cyrin
38f9e1622d
add environment variable support 🎉 2019-08-01 22:52:21 -07:00
Lynn Cyrin
f21b22dd90
cleanup some issues with error display 2019-08-01 22:10:18 -07:00
Lynn Cyrin
9438aba3b8
remove showFlagError, we can use the help printer assertion to accomplish the same goal 2019-08-01 19:54:57 -07:00
Lynn Cyrin
23f09ac1e8
cleanup tests, check required flags in more places 2019-07-28 22:19:35 -07:00
Lynn Cyrin
3d2d6975b4
reduce diff 2019-07-11 20:32:42 -07:00
Lynn Cyrin
0608059cc7
reduce diff 2019-07-11 20:32:15 -07:00
Lynn Cyrin
138dbaafec
Merge branch 'master' into required_flags 2019-07-11 20:07:55 -07:00
Gábor Lipták
9587fc27bd
Correct typo 2018-10-18 20:56:13 -04:00
Valentin Rothberg
c23dfba701 short opt handling: fix parsing
Only split a given string (e.g., "-abc") into short options (e.g., "-a",
"-b", "-c") if all those are flags.  To further avoid mistakenly
transform common arguments, catch "flag provided but not defined" errors
to iteratively transform short options.

Signed-off-by: Valentin Rothberg <vrothberg@suse.com>
Fixes: https://github.com/projectatomic/libpod/issues/714
2018-08-20 12:35:43 +02:00
Nico Windler
3a87b13b01 Fix args reordering when bool flags are present 2018-02-10 14:00:34 +01:00
Jesse Szwedko
e38e4ae2d0 Fix regression of SkipFlagParsing behavior
Introduced by df562bf1a8

Was mistakenly prepending the command name.
2017-12-29 13:38:18 -05:00
Jesse Szwedko
df562bf1a8 Refactor flag handling logic
Refactor logic introduced by #686
2017-12-03 13:38:50 -08:00
baude
ceaac7c915 Handle ShortOptions and SkipArgReorder
There was a bug in parsing when both ShortOptions
and SkipArgReorder were being used together.

Signed-off-by: baude <bbaude@redhat.com>
2017-11-29 09:22:26 -06:00
baude
fd5382e7a5 Combine bool short names
Adds the ability to allow the combination of bool
short-name options.  For example,

cmd foobar -ov

This is done through a bool "UseShortOptionHandler" set in
the command struct.

Built upon PR #621

Signed-off-by: baude <bbaude@redhat.com>
2017-11-13 16:29:20 -06:00
zhuchensong
43c8c02cf5 Support POSIX-style short flag combining 2017-11-08 16:05:47 -06:00
Robert Liebowitz
b44660ac3d Consider case when sorting strings
This makes sorting flags and other sections consistent with how most
command line tools function, by placing both flags `-A` and `-a` before
a flag `-B`.
2017-10-28 03:00:11 -04:00
Tyler Davis
530df59178 Pass context into handleExitCoder 2017-06-28 09:52:12 -07:00
Tyler Davis
9d61cbad02 Updated command.go to use App handleExitCoder 2017-06-28 09:41:08 -07:00
Jesse Szwedko
c64d74a5d9 Do not double print errors from Before()
They should be handled by HandleExitCoder() as `After()` errors are.
2017-06-24 19:57:19 -07:00
Joe Richey joerichey@google.com
291122b8f0 Subcommand OnUsageError should be passed to app
Not all of the Command components were being passed to the created App
in the startApp function.
2017-06-21 17:55:49 -07:00
Harshavardhana
f7d6a07f2d Add support for custom help templates. 2017-05-08 09:53:53 -07:00
Jesse Szwedko
87fe13079e Rely on Command context in Run()
Was previously relying on the parent context which caused things like
`.Command` to not be available to OnUsageError().

Fixes #609
2017-04-24 15:19:34 -07:00
Jesse Szwedko
9913f0cef2 Merge branch 'master' into subcommand-structure 2017-01-28 13:35:02 -08:00
Joe Richey
e109e81e6a Subcommand structure should be correctly copied to main structure 2017-01-23 10:36:28 -08:00
Robert Bittle
4ed366e201
Pass the ErrWriter on the root app to subcommands 2017-01-18 23:29:26 -05:00
Joe Richey
0083ae8732 Usage/Description/ArgsUsage correctly copied when using subcommand 2017-01-09 15:57:49 -08:00
Maximilian Meister
ac772237b9
command: enable ordering commands by name 2017-01-09 16:40:32 +01:00
Joshua Rubin
2da42640ad
Merge remote-tracking branch 'origin/master' into completion_fix 2016-11-18 09:28:39 -07:00
Jesse Szwedko
e367fafa3d Return an error when parsing environment variables for values fails
Currently cli silently (aside from IntSlice and Int64Slice which oddly
printed directly to the error stream) ignores failures that occur when
parsing environment variables for their value for flags that define
environment variables. Instead, we should propogate up the error to the
user.

This is accomplished in a backwards compatible manner by adding a new,
internal, interface which defines an applyWithError function that all
flags here define. In v2, when we can modify the interface, we can drop
this secondary interface and modify `Apply` to return an error.
2016-11-13 14:59:35 -08:00
Jesse Szwedko
0113f56d10 If no action is specified on the command or app, print the help documentation
Rather than panic'ing or displaying an opaque error message about the
signature which is more confusing to the end user.

Fixes #562
2016-11-12 13:37:07 -08:00
Joshua Rubin
ea3df26e64
make shell autocomplete more robust 2016-11-04 14:56:28 -06:00
Richard Kovacs
4cc2bad36e Display error instead of just say command is incorrect 2016-10-19 13:31:05 +02:00
Shukui Yang
5d108a4435 bug fix when SkipFlagParsing is false and SkipArgReorder is true
Signed-off-by: Shukui Yang <yangshukui@huawei.com>
2016-09-12 21:30:33 +08:00
Frances Bar
3df4b71842 Backport no argument reordering as an option
In the unreleased version 2, the argument reordering has been removed
(in f585ec7cb8) since it only worked if
all of the arguments appeared before all of the flags, but not if they
were intermixed which was of limited utility and caused some confusion.
This commit allows enabling of this future behavior via SkipArgReorder.

Ideally we'd support complete intermingling of flags and arguments, but
this is unlikely to happen until we switch flag parsers.

Fixes #515
2016-09-11 12:04:35 -07:00
Matt Farina
07ce8bf79c Cleaned up else per golint
When an if ends in a return the else is not required. golint
detects these conditions and found these.
2016-05-09 10:15:05 -04:00
Matt Farina
2f110bd745 Cleaned up exported func comments per golint 2016-05-09 10:12:59 -04:00
Dan Buch
5c641d69b4
Merge branch 'hidden_command' of https://github.com/psmit/cli into psmit-hidden_command 2016-05-03 05:50:36 -04:00
Dan Buch
fed78b8bab
Rework of hidden flag impl plus some Action func corrections 2016-05-01 08:36:17 -04:00
e671f0b23b Merge pull request #339 from jack230230/master
Add App.Metadata
2016-04-30 09:36:46 -04:00
王振威
f72d405107 Change Extras to Metadata 2016-04-30 10:42:07 +08:00
Dan Buch
d45f7c1fe2
Allow for legacy and newer Action func signatures 2016-04-27 11:34:01 -04:00
Dan Buch
f688d47415
Encapsulate ExitCoder check into a lil func 2016-04-27 09:18:42 -04:00
Dan Buch
b7329f4968
Switch from multi-return with exit codes to ExitCoder check 2016-04-27 09:12:34 -04:00
Dan Buch
a17c8cf1d8
Rename func type suffixes Fn->Func and add OnUsageErrorFunc 2016-04-25 18:29:05 -04:00
Dan Buch
10c8309d84
Merge branch 'develop' of https://github.com/txgruppi/cli into txgruppi-develop 2016-04-25 18:10:10 -04:00
Jesse Szwedko
042842b819 Remove CategorizedHelp from App and allow subcommands to have categories
Just place all subcommands in categories, the default category will be
"" which will properly format the output (and group commands that have
no category).

Also allow subcommands to have categories.

Lastly, augment the test to check the output.
2016-03-20 12:17:13 -07:00
Soulou
a0801792cc Allow to sort commands by category 2016-03-20 11:32:58 -07:00
王振威
88ea7cbec8 Add App extras info 2016-03-02 10:45:13 +08:00
Uwe Dauernheim
a755a95d01 Fix semantic typo 2016-02-17 14:51:16 +00:00