mirror of
https://github.com/facebook/sapling.git
synced 2025-01-04 03:06:30 +03:00
dispatch: do not show help on CommandError
Summary:
CommandError happens if there is an unknown command flag, or a required
argument is missing. The old behavior is to print an error message to
stderr, then start the pager with the command help printed to stdout.
There are 2 problems with that approach:
1. When using mosh, a long help text might flush the actual error to out of the
screen. The error message will be missed.
2. When captured in shell scripts, the help text printed to stdout would be
captured, which is almost always undesirable.
The actual motivation of this change is for 2. Zsh themes like bullet-train [1]
uses `hg id -b 2>/dev/null` and we'd like to remove `id -b` support. After that,
the command should not polluate stdout with help text.
[1]: bd88ade263/bullet-train.zsh-theme (L102)
Differential Revision: D14151200
fbshipit-source-id: edd38e91115f96929438379aa2e40edfba560b41
This commit is contained in:
parent
fba42ecd00
commit
2dc2a3d2a2
@ -591,14 +591,12 @@ def _callcatch(ui, func):
|
||||
)
|
||||
except error.CommandError as inst:
|
||||
if inst.args[0]:
|
||||
ui.pager("help")
|
||||
msgbytes = pycompat.bytestr(inst.args[1])
|
||||
ui.warn(_("hg %s: %s\n") % (inst.args[0], msgbytes))
|
||||
commands.help_(ui, inst.args[0], full=False, command=True)
|
||||
ui.warn(_("(use 'hg %s -h' to get help)\n") % (inst.args[0],))
|
||||
else:
|
||||
ui.pager("help")
|
||||
ui.warn(_("hg: %s\n") % inst.args[1])
|
||||
commands.help_(ui)
|
||||
ui.warn(_("(use 'hg -h' to get help)\n"))
|
||||
except error.ParseError as inst:
|
||||
_formatparse(ui.warn, inst)
|
||||
return -1
|
||||
|
@ -454,182 +454,22 @@ invalid arguments
|
||||
|
||||
$ hg rt foo
|
||||
hg rt: invalid arguments
|
||||
hg rt
|
||||
|
||||
alias for: hg root
|
||||
|
||||
(use 'hg rt -h' to show more help)
|
||||
(use 'hg rt -h' to get help)
|
||||
[255]
|
||||
|
||||
invalid global arguments for normal commands, aliases, and shell aliases
|
||||
|
||||
$ hg --invalid root
|
||||
hg: option --invalid not recognized
|
||||
Mercurial Distributed SCM
|
||||
|
||||
hg COMMAND [OPTIONS]
|
||||
|
||||
These are some common Mercurial commands. Use 'hg help commands' to list all
|
||||
commands, and 'hg help COMMAND' to get help on a specific command.
|
||||
|
||||
Get the latest commits from the server:
|
||||
|
||||
pull pull changes from the specified source
|
||||
|
||||
View commits:
|
||||
|
||||
show show commit in detail
|
||||
diff show differences between commits
|
||||
|
||||
Check out a commit:
|
||||
|
||||
checkout check out a specific commit
|
||||
|
||||
Work with your checkout:
|
||||
|
||||
status list files with pending changes
|
||||
add start tracking the specified files
|
||||
remove delete the specified tracked files
|
||||
forget stop tracking the specified files
|
||||
revert change the specified files to match a commit
|
||||
|
||||
Commit changes and modify commits:
|
||||
|
||||
commit save all pending changes or specified files in a new commit
|
||||
|
||||
Rearrange commits:
|
||||
|
||||
rebase move commits from one location to another
|
||||
graft copy commits from a different location
|
||||
|
||||
Undo changes:
|
||||
|
||||
uncommit uncommit part or all of the current commit
|
||||
|
||||
Other commands:
|
||||
|
||||
config show config settings
|
||||
grep search for a pattern in tracked files in the working directory
|
||||
|
||||
Additional help topics:
|
||||
|
||||
filesets specifying files by their characteristics
|
||||
glossary common terms
|
||||
patterns specifying files by file name pattern
|
||||
revisions specifying commits
|
||||
templating customizing output with templates
|
||||
(use 'hg -h' to get help)
|
||||
[255]
|
||||
$ hg --invalid mylog
|
||||
hg: option --invalid not recognized
|
||||
Mercurial Distributed SCM
|
||||
|
||||
hg COMMAND [OPTIONS]
|
||||
|
||||
These are some common Mercurial commands. Use 'hg help commands' to list all
|
||||
commands, and 'hg help COMMAND' to get help on a specific command.
|
||||
|
||||
Get the latest commits from the server:
|
||||
|
||||
pull pull changes from the specified source
|
||||
|
||||
View commits:
|
||||
|
||||
show show commit in detail
|
||||
diff show differences between commits
|
||||
|
||||
Check out a commit:
|
||||
|
||||
checkout check out a specific commit
|
||||
|
||||
Work with your checkout:
|
||||
|
||||
status list files with pending changes
|
||||
add start tracking the specified files
|
||||
remove delete the specified tracked files
|
||||
forget stop tracking the specified files
|
||||
revert change the specified files to match a commit
|
||||
|
||||
Commit changes and modify commits:
|
||||
|
||||
commit save all pending changes or specified files in a new commit
|
||||
|
||||
Rearrange commits:
|
||||
|
||||
rebase move commits from one location to another
|
||||
graft copy commits from a different location
|
||||
|
||||
Undo changes:
|
||||
|
||||
uncommit uncommit part or all of the current commit
|
||||
|
||||
Other commands:
|
||||
|
||||
config show config settings
|
||||
grep search for a pattern in tracked files in the working directory
|
||||
|
||||
Additional help topics:
|
||||
|
||||
filesets specifying files by their characteristics
|
||||
glossary common terms
|
||||
patterns specifying files by file name pattern
|
||||
revisions specifying commits
|
||||
templating customizing output with templates
|
||||
(use 'hg -h' to get help)
|
||||
[255]
|
||||
$ hg --invalid blank
|
||||
hg: option --invalid not recognized
|
||||
Mercurial Distributed SCM
|
||||
|
||||
hg COMMAND [OPTIONS]
|
||||
|
||||
These are some common Mercurial commands. Use 'hg help commands' to list all
|
||||
commands, and 'hg help COMMAND' to get help on a specific command.
|
||||
|
||||
Get the latest commits from the server:
|
||||
|
||||
pull pull changes from the specified source
|
||||
|
||||
View commits:
|
||||
|
||||
show show commit in detail
|
||||
diff show differences between commits
|
||||
|
||||
Check out a commit:
|
||||
|
||||
checkout check out a specific commit
|
||||
|
||||
Work with your checkout:
|
||||
|
||||
status list files with pending changes
|
||||
add start tracking the specified files
|
||||
remove delete the specified tracked files
|
||||
forget stop tracking the specified files
|
||||
revert change the specified files to match a commit
|
||||
|
||||
Commit changes and modify commits:
|
||||
|
||||
commit save all pending changes or specified files in a new commit
|
||||
|
||||
Rearrange commits:
|
||||
|
||||
rebase move commits from one location to another
|
||||
graft copy commits from a different location
|
||||
|
||||
Undo changes:
|
||||
|
||||
uncommit uncommit part or all of the current commit
|
||||
|
||||
Other commands:
|
||||
|
||||
config show config settings
|
||||
grep search for a pattern in tracked files in the working directory
|
||||
|
||||
Additional help topics:
|
||||
|
||||
filesets specifying files by their characteristics
|
||||
glossary common terms
|
||||
patterns specifying files by file name pattern
|
||||
revisions specifying commits
|
||||
templating customizing output with templates
|
||||
(use 'hg -h' to get help)
|
||||
[255]
|
||||
|
||||
environment variable changes in alias commands
|
||||
|
@ -4,7 +4,7 @@
|
||||
Empty
|
||||
$ hg log --configfile | head -1
|
||||
hg log: option --configfile requires argument
|
||||
hg log [OPTION]... [FILE]
|
||||
(use 'hg log -h' to get help)
|
||||
|
||||
Simple file
|
||||
$ cat >> $TESTTMP/simple.rc <<EOF
|
||||
|
@ -15,27 +15,14 @@ Missing arg:
|
||||
|
||||
$ hg cat
|
||||
hg cat: invalid arguments
|
||||
hg cat [OPTION]... FILE...
|
||||
|
||||
output the current or given revision of files
|
||||
|
||||
Options ([+] can be repeated):
|
||||
|
||||
-o --output FORMAT print output to file with formatted name
|
||||
-r --rev REV print the given revision
|
||||
--decode apply any matching decode filter
|
||||
-I --include PATTERN [+] include names matching the given patterns
|
||||
-X --exclude PATTERN [+] exclude names matching the given patterns
|
||||
|
||||
(use 'hg cat -h' to show more help)
|
||||
(use 'hg cat -h' to get help)
|
||||
[255]
|
||||
|
||||
Missing parameter for early option:
|
||||
|
||||
$ hg log -R 2>&1 | grep 'hg log'
|
||||
hg log: option -R requires argument
|
||||
hg log [OPTION]... [FILE]
|
||||
(use 'hg log -h' to show more help)
|
||||
(use 'hg log -h' to get help)
|
||||
|
||||
"--" may be an option value:
|
||||
|
||||
@ -113,8 +100,7 @@ applied before the command name is resolved:
|
||||
|
||||
$ hg log -b '--config=alias.log=log --config=hooks.pre-log=false'
|
||||
hg log: option -b not recognized
|
||||
error in definition for alias 'log': --config may only be given on the command
|
||||
line
|
||||
(use 'hg log -h' to get help)
|
||||
[255]
|
||||
|
||||
$ hg log -b '--config=defaults.log=--config=hooks.pre-log=false'
|
||||
|
@ -839,11 +839,7 @@ Test help topic with same name as extension
|
||||
|
||||
$ hg multirevs
|
||||
hg multirevs: invalid arguments
|
||||
hg multirevs ARG
|
||||
|
||||
multirevs command
|
||||
|
||||
(use 'hg multirevs -h' to show more help)
|
||||
(use 'hg multirevs -h' to get help)
|
||||
[255]
|
||||
|
||||
|
||||
|
@ -126,6 +126,7 @@ Test exception logging:
|
||||
Note: Errors raised by the dispatch logic aren't logged here:
|
||||
$ hg st --nonexistant > /dev/null
|
||||
hg status: option --nonexistant not recognized
|
||||
(use 'hg status -h' to get help)
|
||||
atexit handler executed
|
||||
[255]
|
||||
>>> import json, pprint
|
||||
|
@ -518,18 +518,7 @@ Test help option with version option
|
||||
|
||||
$ hg add --skjdfks
|
||||
hg add: option --skjdfks not recognized
|
||||
hg add [OPTION]... [FILE]...
|
||||
|
||||
start tracking the specified files
|
||||
|
||||
Options ([+] can be repeated):
|
||||
|
||||
-I --include PATTERN [+] include names matching the given patterns
|
||||
-X --exclude PATTERN [+] exclude names matching the given patterns
|
||||
-S --subrepos recurse into subrepositories
|
||||
-n --dry-run do not perform actions, just print output
|
||||
|
||||
(use 'hg add -h' to show more help)
|
||||
(use 'hg add -h' to get help)
|
||||
[255]
|
||||
|
||||
Test ambiguous command help
|
||||
|
@ -29,6 +29,7 @@ Make sure to enable tracking
|
||||
$ hg book bmtrackingremote --track default/bookmarkonremote
|
||||
$ hg pull --rebase > /dev/null
|
||||
hg pull: option --rebase not recognized
|
||||
(use 'hg pull -h' to get help)
|
||||
[255]
|
||||
|
||||
Tests 'hg pull --rebase' rebases from the active tracking bookmark onto the appropriate remote changes.
|
||||
|
@ -600,23 +600,7 @@ Make sure no one adds back a -b option:
|
||||
|
||||
$ hg strip -b tip
|
||||
hg strip: option -b not recognized
|
||||
hg strip [-k] [-f] [-B bookmark] [-r] REV...
|
||||
|
||||
strip changesets and all their descendants from the repository
|
||||
|
||||
(use 'hg help -e strip' to show help for the strip extension)
|
||||
|
||||
Options ([+] can be repeated):
|
||||
|
||||
-r --rev REV [+] strip specified revision (optional, can specify
|
||||
revisions without this option)
|
||||
-f --force force removal of changesets, discard uncommitted
|
||||
changes (no backup)
|
||||
--no-backup no backups
|
||||
-k --keep do not modify working directory during strip
|
||||
-B --bookmark VALUE [+] remove revs only reachable from given bookmark
|
||||
|
||||
(use 'hg strip -h' to show more help)
|
||||
(use 'hg strip -h' to get help)
|
||||
[255]
|
||||
|
||||
$ cd ..
|
||||
|
@ -126,33 +126,13 @@
|
||||
|
||||
$ hg othertest
|
||||
hg othertest: invalid arguments
|
||||
hg othertest [SUBCOMMAND]
|
||||
|
||||
other test command
|
||||
|
||||
Subcommands:
|
||||
|
||||
alpha other test subcommand alpha
|
||||
|
||||
(use 'hg help othertest SUBCOMMAND' to show complete subcommand help)
|
||||
|
||||
(use 'hg othertest -h' to show more help)
|
||||
(use 'hg othertest -h' to get help)
|
||||
[255]
|
||||
$ hg othertest foo
|
||||
other test command called with 'foo'
|
||||
$ hg othertest alpha
|
||||
hg othertest alpha: invalid arguments
|
||||
hg othertest alpha
|
||||
|
||||
other test subcommand alpha
|
||||
|
||||
Subcommands:
|
||||
|
||||
beta other test subcommand alpha subcommand beta
|
||||
|
||||
(use 'hg help othertest alpha SUBCOMMAND' to show complete subcommand help)
|
||||
|
||||
(use 'hg othertest alpha -h' to show more help)
|
||||
(use 'hg othertest alpha -h' to get help)
|
||||
[255]
|
||||
$ hg othertest alfa foo
|
||||
other test command alpha called with 'foo'
|
||||
@ -160,17 +140,7 @@
|
||||
other test command alpha/beta called
|
||||
$ hg yt
|
||||
hg yt: invalid arguments
|
||||
hg yt [SUBCOMMAND]
|
||||
|
||||
alias for: hg othertest
|
||||
|
||||
Subcommands:
|
||||
|
||||
alpha other test subcommand alpha
|
||||
|
||||
(use 'hg help yt SUBCOMMAND' to show complete subcommand help)
|
||||
|
||||
(use 'hg yt -h' to show more help)
|
||||
(use 'hg yt -h' to get help)
|
||||
[255]
|
||||
$ hg yta foo
|
||||
other test command alpha called with 'foo'
|
||||
|
Loading…
Reference in New Issue
Block a user