Commit 2440c5a9 authored by Mike Frysinger's avatar Mike Frysinger Committed by Commit Bot

grit: delay "help" builtin parsing

The "help" ad-hoc parsing only works in the simplest case:
  grit help
  grit help foo

When passing options to grit, the "help" builtin fails and producing
confusing output:
  $ grit -i ... help
  No such tool.  Try running 'grit help' for a list of tools.
  $ grit -i ... help xmb
  No such tool.  Try running 'grit help' for a list of tools.

Delay parsing of the "help" tool until after we've processed grit's
core options.

Bug: 747171
Change-Id: Iae5fdee2493346cee4272368ac8862647433faaf
Reviewed-on: https://chromium-review.googlesource.com/c/1320690Reviewed-by: default avataragrieve <agrieve@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605854}
parent a6966377
...@@ -196,64 +196,65 @@ def Main(args): ...@@ -196,64 +196,65 @@ def Main(args):
"""Parses arguments and does the appropriate thing.""" """Parses arguments and does the appropriate thing."""
util.ChangeStdoutEncoding() util.ChangeStdoutEncoding()
if not args or (len(args) == 1 and args[0] == 'help'): options = Options()
PrintUsage() try:
return 0 args = options.ReadOptions(args) # args may be shorter after this
elif len(args) == 2 and args[0] == 'help': except getopt.GetoptError as e:
tool = args[1].lower() print "grit:", str(e)
if not _GetToolInfo(tool): print "Try running 'grit help' for valid options."
print "No such tool. Try running 'grit help' for a list of tools." return 1
return 2 if not args:
print "No tool provided. Try running 'grit help' for a list of tools."
print ("Help for 'grit %s' (for general help, run 'grit help'):\n" return 2
% (tool))
print _GetToolInfo(tool)[_FACTORY]().__doc__ tool = args[0]
return 0 if tool == 'help':
else: if len(args) == 1:
options = Options() PrintUsage()
try: return 0
args = options.ReadOptions(args) # args may be shorter after this else:
except getopt.GetoptError as e: tool = args[1]
print "grit:", str(e) if not _GetToolInfo(tool):
print "Try running 'grit help' for valid options." print "No such tool. Try running 'grit help' for a list of tools."
return 1 return 2
if not args:
print "No tool provided. Try running 'grit help' for a list of tools." print ("Help for 'grit %s' (for general help, run 'grit help'):\n"
return 2 % (tool))
tool = args[0] print _GetToolInfo(tool)[_FACTORY]().__doc__
if not _GetToolInfo(tool): return 0
print "No such tool. Try running 'grit help' for a list of tools." if not _GetToolInfo(tool):
return 2 print "No such tool. Try running 'grit help' for a list of tools."
return 2
try:
if _GetToolInfo(tool)[_REQUIRES_INPUT]: try:
os.stat(options.input) if _GetToolInfo(tool)[_REQUIRES_INPUT]:
except OSError: os.stat(options.input)
print ('Input file %s not found.\n' except OSError:
'To specify a different input file:\n' print ('Input file %s not found.\n'
' 1. Use the GRIT_INPUT environment variable.\n' 'To specify a different input file:\n'
' 2. Use the -i command-line option. This overrides ' ' 1. Use the GRIT_INPUT environment variable.\n'
'GRIT_INPUT.\n' ' 2. Use the -i command-line option. This overrides '
' 3. Specify neither GRIT_INPUT or -i and GRIT will try to load ' 'GRIT_INPUT.\n'
"'resource.grd'\n" ' 3. Specify neither GRIT_INPUT or -i and GRIT will try to load '
' from the current directory.' % options.input) "'resource.grd'\n"
return 2 ' from the current directory.' % options.input)
return 2
if options.hash:
grit.extern.FP.UseUnsignedFingerPrintFromModule(options.hash) if options.hash:
grit.extern.FP.UseUnsignedFingerPrintFromModule(options.hash)
try:
toolobject = _GetToolInfo(tool)[_FACTORY]() try:
if options.profile_dest: toolobject = _GetToolInfo(tool)[_FACTORY]()
import hotshot if options.profile_dest:
prof = hotshot.Profile(options.profile_dest) import hotshot
return prof.runcall(toolobject.Run, options, args[1:]) prof = hotshot.Profile(options.profile_dest)
else: return prof.runcall(toolobject.Run, options, args[1:])
return toolobject.Run(options, args[1:]) else:
except getopt.GetoptError as e: return toolobject.Run(options, args[1:])
print "grit: %s: %s" % (tool, str(e)) except getopt.GetoptError as e:
print "Try running 'grit help %s' for valid options." % (tool,) print "grit: %s: %s" % (tool, str(e))
return 1 print "Try running 'grit help %s' for valid options." % (tool,)
return 1
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment