Commit Graph

158 Commits

Author SHA1 Message Date
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
Jesse Szwedko
83497d2cda Merge remote-tracking branch 'origin/master' into v2-merge 2016-10-29 14:13:18 -07: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
Antoine Eiche
94bc26fd1c Refactoring names from bash to shell
The refactoring is required since completion is also supported for zsh
shell.

Refactoring details:
- flag generate-bash-completion -> generate-completion
- var  EnableBashCompletion     -> EnableShellCompletion
- var  BashComplete             -> ShellComplete
- var  BashCompletionFlag       -> GenerateCompletionFlag
- type BashCompleteFunc         -> ShellCompleteFunc
2016-07-26 15:32:03 +02:00
Dan Buch
df685fbacc
Remove NewApp initializer
and move defaulting to `App.Setup`
2016-06-22 12:47:57 -04:00
Dan Buch
3d75e9e711
Go with interfaces + private opaque types
rather than public types that wrap slices
2016-05-25 12:05:14 -04:00
c70993dbc5 Merge branch 'v2' into minimize-struct-copying 2016-05-23 22:08:59 -04:00
Dan Buch
a41a43b00f
Switch to fmt.Fprintf for displaying usage error 2016-05-23 22:03:19 -04:00
Dan Buch
8f25dbb615
Ensure all flag aliases are set when Destination given
and extend "Incorrect Usage" message to show the error.

Closes #430
2016-05-23 22:00:59 -04:00
Dan Buch
61710ff108
Make slice wrapping pattern more consistent
and move *Args out into its own file
2016-05-23 20:15:35 -04:00
Dan Buch
cd10b49473
Minimize struct copying
by using pointer func receivers and slices of struct pointers where possible.
2016-05-22 15:20:52 -04:00
Dan Buch
81fcf706ea
Replace all "stringly typed" fields with slice equivalents
and alter the Flag interface accordingly

Closes #415
2016-05-21 21:29:45 -04:00
Dan Buch
c19dbaf230
Remove deprecated things and supporting code 2016-05-17 15:11:44 -04:00
Dan Buch
32ebecfbb5
Merge remote-tracking branch 'origin/master' into v2 2016-05-09 11:18:21 -04: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
bac790c819
Merge remote-tracking branch 'origin/master' into v2 2016-05-09 08:00:13 -04:00
Jesse Szwedko
f585ec7cb8 Remove reordering of flags and arguments
This was introduced by #36, but only worked in the specific case of all
arguments being passed before all flags. If the user mixed them, they
ended up with odd parsing behavior where the arguments were reordered
(causing #103 and #355).

Given the tradeoffs I think we should remove support for flag
reordering.

Fixes #103
Fixes #355
2016-05-07 16:36:54 -07: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
Jesse Szwedko
d5f087da9d Merge pull request #289 from KSubedi/master
Added command to have a custom text on the USAGE section of help
2016-02-06 13:12:10 -08:00
Gregor Noczinski
66c1742012 * Fixed typos 2016-02-06 21:39:35 +01: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
Andreas Kupries
bb4e78eb6a Fixed mishandling of a "-"(dash)-argument causing reordering of cli non-flag arguments.
Added test demonstrating issue (PASS with fix, FAIL without).
2016-01-26 15:34:53 -08:00
Gregor Noczinski
f3c8e07836 Also show help if App/Command Before produces error. 2015-12-25 22:08:22 +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
Jesse Szwedko
6191d931b7 When skipping flag parsing, still parse into arguments
Fool the FlagSet into thinking that all arguments are actually
arguments rather than attempting to parse them as flags.
2015-10-29 20:16:35 -07:00
Jesse Szwedko
bc3cb33cef Actually skip parsing of flags if SkipFlagParsing is set
Previous just skipped if firstFlagIndex was > -1
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
Kaushal Subedi
8b46886de8 added flag to have a custom text on the USAGE section of help 2015-10-24 23:37:21 -06:00
Tristan Zajonc
c7aac252f1 add tests 2015-08-12 22:14:26 -07:00
Tristan Zajonc
cc46ca1020 allow overriding help name 2015-08-12 21:58:25 -07:00
Tristan Zajonc
aced6e8739 fix tests 2015-08-12 21:43:14 -07:00
Tristan Zajonc
ecb0b5ac0a improve help by including parent command for subcommands 2015-08-12 20:00:07 -07:00
Tristan Zajonc
ef65245544 add ArgsUsage to App and Command 2015-08-12 20:00:07 -07:00
Tarcísio Gruppi
49c1229409
Added exit code support
Now the exit code can be returned by BeforeFn, ActionFn and AfterFn.

The `os.Exit` function is not called by this packaged

This closes #66 and closes #164
2015-07-28 20:10:08 +02:00
Tarcísio Gruppi
9c0db3f4ac
Created types for functions
The function used by BashComplete, Before, After, Action and
CommandNotFound have their won type.

This makes easier to change/update the API
2015-07-28 20:02:18 +02:00
Brian Goff
758ad1e836 Sets a subcommand's parent cmd
This allows the help output to show the correct/full command path to the
subcommand.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2015-07-02 14:47:49 -04:00
Martin Falatic
ee2cde7a77 Print blank lines in help and error outputs more consistently. 2015-06-24 22:46:33 -07:00
Fabian Ruff
65d50017d4 search context hierachy for global flags 2015-05-18 23:21:33 +02:00
jszwedko
a889873af5 Set additional information on command's 'app'
For completeness
2015-05-03 18:42:21 -07:00
jszwedko
b8104e5da7 Set writer when running command as app
Also add test from https://github.com/codegangsta/cli/pull/202 with
slight modifications.
2015-05-03 18:37:51 -07: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
Nicolas Dufour
4be878bffc Fixing the issue with a command with subcommands not showing help message.
- the command name is "" and HasName was returning true for an empty
  ShortName.
- the Show method wasn't aware that command name was just "" and
  returned the first subcommand.
2015-02-23 08:32:31 -05:00
jszwedko
50c77ecec0 Fix comments for .After field on Command and App 2015-02-20 16:23:36 -05:00
Peter Smit
5308b4cd0f Allow commands to be hidden from help and autocomplete 2015-02-06 10:46:32 +02:00
Dario Castañé
4e3a83b43e Merge branch 'master' of https://github.com/codegangsta/cli
Conflicts:
	app.go
	app_test.go
2015-01-10 00:35:11 +01:00
Jesse Szwedko
bf4a526f48 Merge pull request #157 from dajulia3/pull_request
stop flag parsing after terminator --
2015-01-09 14:04:33 -05:00
5b9e204508 Merge pull request #153 from codegangsta/allow-hiding-of-help-flag
Allow hiding of help flag without hiding help subcommand
2015-01-08 14:49:36 -05:00
Matthew McNew
d05d895492 stop flag parsing after terminator --
Signed-off-by: David Wadden <dwadden@pivotal.io>
2014-12-17 09:56:05 -06:00
jszwedko
e72094e6a4 Prefer fmt.Fprint* functions over io.WriteString
Less composition needed.
2014-12-01 23:57:35 -05:00
jszwedko
b8c8282de5 Merge remote-tracking branch 'origin/master' into allow-writer-to-be-set
Conflicts:
	app.go
	help.go
2014-12-01 23:51:35 -05:00
jszwedko
0d4870d63e Rename Stdout -> Writer 2014-12-01 23:50:04 -05:00
jszwedko
780f839a02 Allow hiding of help flag without hiding help subcommand
By utilizing struct zero value
2014-12-01 23:21:22 -05:00
Dario Castañé
44efc2952d Added Before method to command and app 2014-11-18 23:44:21 +01:00
Kyle Allan
156cd267e5 move to CommandNotFound copy to startApp 2014-07-25 10:06:04 -07:00
Audrius Butkevicius
4a645835f0 Add HideHelp flag in App and Command 2014-07-13 18:51:09 +01:00
John Hopper
60e3dcaf6d Allow a writer to be set that represents Stdout so that redirection of App output may occur. 2014-06-12 02:27:15 -07:00
Summer Mousa
a911ec75e4 Can now change these default flags in other applications 2014-04-29 09:21:19 -05:00
Jeremy Saenz
73aae5979c Merge pull request #80 from wendorf/master
Add SkipFlagParsing option to Command
2014-04-22 20:34:36 -07:00
Jeremy Saenz
a502865bb7 Merge pull request #74 from Winslett/context-accessible-command
Make Command accessible from Context
2014-04-22 20:33:02 -07:00
Summer Mousa
2535376782 If the Subcommand is instantiated, via the Before method and has no subcommands, display the CommandHelp instead of the SubcommandHelp 2014-04-17 11:48:00 -05:00
Summer Mousa
faf2a3d4a3 Added Before method to command. If set, or if command.Subcommands is set, then the command is treated as a recursive subcommand 2014-04-16 15:26:28 -05:00
Summer Mousa
13f0c8c0f6 More consistent implementation of recursive subcommands 2014-04-16 11:18:00 -05:00
Dan Wendorf and Karen Wang
6c5f810d8f Add SkipFlagParsing option to Command 2014-04-14 14:44:32 -07:00
Summer Mousa
3a10545f91 Made bash completion command optional; still need to update documentation 2014-04-12 08:32:53 -05:00
Summer Mousa
0b29bee364 merging code 2014-04-10 12:14:13 -05:00
Chris Winslett
c69522c960 Make Command accessible from Context 2014-03-29 12:02:05 -07:00
Jeremy Saenz
01b889e637 Merge branch 'master' of github.com:xyproto/cli into xyproto-master
Conflicts:
	app.go
	context.go
2013-11-28 07:51:31 -08:00
Alexander Rødseth
1bea6dcbf0 Custom type for arguments 2013-11-24 14:40:21 +01:00
Jeremy Saenz
ab6f1b7c3c Formatting 2013-11-20 17:25:13 -08:00
Jeremy Saenz
4120b604ec Removed help flag. we no longer need it. 2013-11-20 17:24:37 -08:00
Jared Forsyth
dc8a62e0e9 refactor, more robust flag propagation 2013-11-20 01:05:18 -07:00
Alexander Rødseth
f93652a890 Fixed all problems/warnings reported by "go vet" 2013-11-15 11:35:24 +01:00
Jeremy Saenz
b25b7a883c JMS #39: Removed all calls to os.Exit(). 2013-11-01 07:33:39 -07:00
Jeremy Saenz
0d3c3f4497 Improved documentation 2013-11-01 07:31:37 -07:00
Thesyncim
4d9038a156 add ability to parse []string types 2013-09-24 02:41:31 +01:00
Damien Le Berrigaud
5d511c7a8b Allow for flags being passed in after arguments 2013-09-18 10:37:03 -06:00