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):
"""Parses arguments and does the appropriate thing."""
util.ChangeStdoutEncoding()
if not args or (len(args) == 1 and args[0] == 'help'):
PrintUsage()
return 0
elif len(args) == 2 and args[0] == 'help':
tool = args[1].lower()
if not _GetToolInfo(tool):
print "No such tool. Try running 'grit help' for a list of tools."
return 2
print ("Help for 'grit %s' (for general help, run 'grit help'):\n"
% (tool))
print _GetToolInfo(tool)[_FACTORY]().__doc__
return 0
else:
options = Options()
try:
args = options.ReadOptions(args) # args may be shorter after this
except getopt.GetoptError as e:
print "grit:", str(e)
print "Try running 'grit help' for valid options."
return 1
if not args:
print "No tool provided. Try running 'grit help' for a list of tools."
return 2
tool = args[0]
if not _GetToolInfo(tool):
print "No such tool. Try running 'grit help' for a list of tools."
return 2
try:
if _GetToolInfo(tool)[_REQUIRES_INPUT]:
os.stat(options.input)
except OSError:
print ('Input file %s not found.\n'
'To specify a different input file:\n'
' 1. Use the GRIT_INPUT environment variable.\n'
' 2. Use the -i command-line option. This overrides '
'GRIT_INPUT.\n'
' 3. Specify neither GRIT_INPUT or -i and GRIT will try to load '
"'resource.grd'\n"
' from the current directory.' % options.input)
return 2
if options.hash:
grit.extern.FP.UseUnsignedFingerPrintFromModule(options.hash)
try:
toolobject = _GetToolInfo(tool)[_FACTORY]()
if options.profile_dest:
import hotshot
prof = hotshot.Profile(options.profile_dest)
return prof.runcall(toolobject.Run, options, args[1:])
else:
return toolobject.Run(options, args[1:])
except getopt.GetoptError as e:
print "grit: %s: %s" % (tool, str(e))
print "Try running 'grit help %s' for valid options." % (tool,)
return 1
options = Options()
try:
args = options.ReadOptions(args) # args may be shorter after this
except getopt.GetoptError as e:
print "grit:", str(e)
print "Try running 'grit help' for valid options."
return 1
if not args:
print "No tool provided. Try running 'grit help' for a list of tools."
return 2
tool = args[0]
if tool == 'help':
if len(args) == 1:
PrintUsage()
return 0
else:
tool = args[1]
if not _GetToolInfo(tool):
print "No such tool. Try running 'grit help' for a list of tools."
return 2
print ("Help for 'grit %s' (for general help, run 'grit help'):\n"
% (tool))
print _GetToolInfo(tool)[_FACTORY]().__doc__
return 0
if not _GetToolInfo(tool):
print "No such tool. Try running 'grit help' for a list of tools."
return 2
try:
if _GetToolInfo(tool)[_REQUIRES_INPUT]:
os.stat(options.input)
except OSError:
print ('Input file %s not found.\n'
'To specify a different input file:\n'
' 1. Use the GRIT_INPUT environment variable.\n'
' 2. Use the -i command-line option. This overrides '
'GRIT_INPUT.\n'
' 3. Specify neither GRIT_INPUT or -i and GRIT will try to load '
"'resource.grd'\n"
' from the current directory.' % options.input)
return 2
if options.hash:
grit.extern.FP.UseUnsignedFingerPrintFromModule(options.hash)
try:
toolobject = _GetToolInfo(tool)[_FACTORY]()
if options.profile_dest:
import hotshot
prof = hotshot.Profile(options.profile_dest)
return prof.runcall(toolobject.Run, options, args[1:])
else:
return toolobject.Run(options, args[1:])
except getopt.GetoptError as e:
print "grit: %s: %s" % (tool, str(e))
print "Try running 'grit help %s' for valid options." % (tool,)
return 1
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