Commit Graph

90 Commits

Author SHA1 Message Date
Matt Farina
2f110bd745 Cleaned up exported func comments per golint 2016-05-09 10:12:59 -04:00
Dan Buch
5a5fa990e1
Merge remote-tracking branch 'origin/master' into exit-nonzero-for-unknown-subcommand 2016-05-09 00:59:36 -04:00
Dan Buch
97d2df6dd7
Merge remote-tracking branch 'origin/master' into psmit-hidden_command 2016-05-08 18:44:38 -04:00
Jesse Szwedko
592f1d97e5 Exit non-zero if a unknown subcommand is given
Currently it just prints the help message and exits 0.

We do this by modifying the helpCommand and helpSubcommand cli.Commands
to return an error if they are called with an unknown subcommand. This
propogates up to the app which exits with 3 and prints the error.

Thanks to @danslimmon for the initial approach!

Fixes #276
2016-05-07 17:26:15 -07:00
Matt Farina
6f0b442222 Update to ErrWriter and make available on app 2016-05-06 12:14:26 -04:00
Matt Farina
2a256d4c53 Provide a variable for writing output with a default of os.Stderr 2016-05-05 10:26:53 -04:00
Dan Buch
cc481d6b0e
Adjust command hiding to use similar convention as hidden flags
plus breaking out "setup" portion of `App.Run` into its own method, cleaning up
some bits of the help templates, and allowing for runtime opt-in of displaying
template errors to stderr.
2016-05-03 06:54:05 -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
Harshavardhana
99431669d0
New `Hide` variable for all Flags
This is a way to provide hidden flags for app, command and subcommands

For example:

  --generate-bash-completion global flag shouldn't be printed along
  with other flags as it might generally confuse people into thinking
  that 'generate' in-fact would generate a bash completion file for them
  to be used along with their app.

Also in general one would want to hide some flags for their apps.
2016-04-30 22:24:27 -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
10c8309d84
Merge branch 'develop' of https://github.com/txgruppi/cli into txgruppi-develop 2016-04-25 18:10:10 -04:00
Jesse Szwedko
bc465beccc Merge pull request #346 from codegangsta/category_sort_2
Add option to make categories with command, to display a more structured help
2016-03-26 15:39:47 -07:00
Radek Simko
d21170f0e3 Never show version if HideVersion=true 2016-03-21 16:12:46 +00: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
d0997e8f99 Set Categories as a read-only method and fix tests 2016-03-20 11:35:26 -07:00
Soulou
994a7028e2 Categories as slice, not a map anymore, order is always preserved 2016-03-20 11:35:25 -07:00
Soulou
a0801792cc Allow to sort commands by category 2016-03-20 11:32:58 -07: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
Matt Butcher
54b6cca78e Remove panic from help.
There is a panic in printHelp that can be trivially triggered when the
shell closes os.Stdout. This happens, for example, when data is piped
between a cli app and something else.

See https://github.com/helm/helm/issues/387
2016-01-20 14:51:55 -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
Ryan Graham
732e97aee8 only display app version and help message once
When processing the flags for -h/--help and -v/--version, only check
the flags in checkVersion() and checkHelp() instead of also printing
the associated message.

This fixes the problem of `app -h` and `app -v` printing their output
twice. The doubling was caused by printing the message once for each
registred alias for the given flags (-h/--help and -v/--version).

Resolves #285
2015-10-18 17:02:23 -07:00
elij
db7af859d2 make help and version parsing use actual specified values
fixes #254
2015-10-13 15:20:36 -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
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
8cae4991af Fixing more formatting 2015-06-25 02:17:26 -07:00
Martin Falatic
4d3820c145 If there are no commands, don't show Commands section. Also fixed Copyright section formatting. 2015-06-25 01:30:54 -07:00
Martin Falatic
595c055010 If Version is an empty string, suppress version output in usage help. 2015-06-24 23:07:32 -07:00
Jesse Szwedko
7ad88c2740 Merge pull request #238 from polds/copyright
Add the ability to add a copyright
2015-06-16 19:39:24 -07:00
Peter Olds
4a11a6ba05 Remove whitespace #238
Signed-off-by: Peter Olds <polds@kyanicorp.com>
2015-06-16 15:23:29 -06:00
Peter Olds
2726643347 Add the ability to add a copyright
Signed-off-by: Peter Olds <polds@kyanicorp.com>
2015-06-09 16:35:50 -06:00
Jesse Szwedko
2272dad83e Version and help check should look for local flags too
Now that Global looks up the chain of contexts, the top level should
access the flags without the prefix (i.e. Bool rather than GlobalBool).
2015-06-02 20:16:44 -07:00
Victor Vieux
7c041f5811 do not print 'AUTHOR(S):' is there is no author
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
2015-05-03 18:01:26 -07:00
jszwedko
e842547421 Readd printHelp function back
But update signature to take a writer. This is a backwards incompatible
change for those overriding the HelpPrinter, but the hope is that this
feature is largely unused and the usage is easily updated.
2015-05-03 17:43:52 -07:00
2bcd11f863 Merge pull request #193 from codegangsta/add-aliases
Add `Command.Aliases` and deprecate `Command.ShortName`
2015-03-16 21:49:33 -04:00
陈小玉
84630daaf4 Update help.go
change template `AUTHOR(s)` tab ident to whitespace.
2015-03-14 01:12:37 +08: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
Jesse Szwedko
3e0905345c Merge pull request #186 from nrdufour/master
Fixing the issue with a command with subcommands not showing help message
2015-03-09 19:37:25 -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
Harrison
c6592bb487 app, help: add backwards compatibility for Authors 2015-02-21 10:44:00 +11:00
Peter Smit
5308b4cd0f Allow commands to be hidden from help and autocomplete 2015-02-06 10:46:32 +02:00
Harrison
3d7183307a app, help: add support for multiple authors 2015-01-31 10:04:52 +11:00
a14c5b47c7 Merge pull request #154 from codegangsta/allow-writer-to-be-set
Allow writer to be set
2014-12-12 08:50:46 -05:00
Jesse Szwedko
e7849f9239 Merge pull request #128 from nbjahan/patch-1
Fixed ShowSubcommandHelp
2014-12-11 20:37:53 -05: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