Commit Graph

40 Commits

Author SHA1 Message Date
Robert Liebowitz
df740f6562 Fix infinite loop flag parsing with short options 2019-10-11 23:00:45 -04:00
Robert Liebowitz
06e3d38d88 Avoid panic for missing flag value
Currently, in cases where a flag value is required but not passed and
short-option handling is enabled, a panic will occur due to a nil
pointer dereference. This prevents that situation from occurring,
instead propagating the appropriate error.
2019-09-13 06:11:09 -04:00
Ajitem Sahasrabuddhe
fdba7e0f8c
linter fixes
code cleanup
changing some test code to ensure uniformity
2019-08-07 20:14:50 +05:30
Valentin Rothberg
3e5a935ed3 fix go vet warning
command_test.go:342:3 value declared but not used

Signed-off-by: Valentin Rothberg <vrothberg@suse.com>
2018-08-21 08:33:42 +02: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
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
0671b166dc Add tests for flag reordering 2017-12-04 09:23:40 -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
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
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
Robert Bittle
4ed366e201
Pass the ErrWriter on the root app to subcommands 2017-01-18 23:29:26 -05: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
Radek Simko
bef215fe3e app: Allocate Metadata map automatically 2016-07-11 07:39:58 +01:00
Matt Farina
2f4ec31264 Fixed spelling and gofmt issues 2016-05-09 09:40:09 -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
Gregor Noczinski
c462071a52 * Added ability to customize usage error messages 2016-02-06 21:39:35 +01:00
leonardyp
6f6e8caf6c Repeat context statement because of a is a pointer
performance  optimization
gofmt  code
2016-02-04 15:25:41 +08:00
Gregor Noczinski
01fdb2cca9 #315 fixed typo 2016-01-20 10:56:46 +01:00
Gregor Noczinski
f90cd56647 Handle Before and After of Command without handling it as subCommand if there is no subCommand. 2015-12-25 21:45:58 +01:00
Håvard Haugen
7b94fd3aad test: avoid output from "go test" when tests pass
Some tests where printing to os.Stdout as a side effect even if the
output was not used/checked in the test.
2015-11-28 18:26:10 +01:00
Nathan LeClaire
3323ab4460 Use a test table and add --help test
Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
2015-10-29 20:17:12 -07:00
Jesse Szwedko
8cd49b108c Update TestCommandIgnoreFlagsIncludingFirstArgument to test for arguments 2015-10-29 20:16:35 -07:00
Nathan LeClaire
c538c376c9 Do not return error when flag parsing should be skipped
Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
2015-10-29 20:16:35 -07:00
Emil Thelin
a9585bb11c Added a flag for TestCommandIgnoreFlags 2015-10-03 17:19:04 +02:00
Tarcísio Gruppi
1510d7e722
Updated tests to support exit code 2015-07-28 20:29:13 +02:00
Edward Sheffler III
8ea1232ede Improve vendoring options by removing self-referential imports in tests. 2015-07-20 12:28:51 -07:00
Fabian Ruff
65d50017d4 search context hierachy for global flags 2015-05-18 23:21:33 +02:00
jszwedko
bf65971a6a Add Command.Aliases and deprecate Command.ShortName
`Aliases` will be more flexible while still allowing "ShortName"
behaviour via `Aliases`.
2015-03-09 21:24:57 -07:00
Josh Mervine
089def51d8 Tweaking tests, removing local import. 2014-08-04 11:30:13 -07:00
Josh Mervine
8f55ca83ff running go fmt 2014-06-17 22:33:30 -07:00
Josh Mervine
7ca86444e8 making all pathing for cli local in tests for easier fork testing 2014-06-17 22:28:33 -07:00
Dan Wendorf and Karen Wang
6c5f810d8f Add SkipFlagParsing option to Command 2014-04-14 14:44:32 -07:00
Jeremy Saenz
ed1ee94250 Adding some docs 2013-07-20 15:50:13 -07:00
Jeremy Saenz
5bb6efd8bd JMS #4: Fixed compile error 2013-07-18 18:04:30 -07:00
Jeremy Saenz
393a533b66 JMS #4: Removing tests from command_test 2013-07-18 18:03:40 -07:00
Jeremy Saenz
3119b075d6 JMS #4: Flag testing 2013-07-18 17:41:22 -07:00
Jeremy Saenz
3f76896c4f JMS #4: Getting some cli tests going. Testing out flags 2013-07-18 17:41:22 -07:00