Commit f30db062 authored by Mike Frysinger's avatar Mike Frysinger Committed by Commit Bot

grit: add --help support to subtools

This makes `grit build --help` work too.

Bug: 747171
Change-Id: I5297019a34446196e625635318f2373620ffd87f
Reviewed-on: https://chromium-review.googlesource.com/c/1339341
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610320}
parent 8a7f841c
......@@ -223,7 +223,7 @@ def Main(args):
print ("Help for 'grit %s' (for general help, run 'grit help'):\n"
% (tool))
print _GetToolInfo(tool)[_FACTORY]().__doc__
_GetToolInfo(tool)[_FACTORY]().ShowUsage()
return 0
if not _GetToolInfo(tool):
print "No such tool. Try running 'grit help' for a list of tools."
......
......@@ -8,6 +8,7 @@
import getopt
import os.path
import StringIO
import sys
from xml.dom import Node
import xml.dom.minidom
......@@ -124,7 +125,8 @@ OPTIONS may be any of the following:
Android2Grd._HEADER_DIR_FLAG,
Android2Grd._XTB_DIR_FLAG,
Android2Grd._XML_DIR_FLAG, ]
(opts, args) = getopt.getopt(args, None, ['%s=' % o for o in flags])
(opts, args) = getopt.getopt(
args, None, ['%s=' % o for o in flags] + ['help'])
for key, val in opts:
# Get rid of the preceding hypens.
......@@ -143,6 +145,9 @@ OPTIONS may be any of the following:
self.xtb_dir = val
elif k == Android2Grd._XML_DIR_FLAG:
self.xml_res_dir = val
elif k == 'help':
self.ShowUsage()
sys.exit(0)
return args
def Run(self, opts, args):
......
......@@ -163,6 +163,7 @@ are exported to translation interchange files (e.g. XMB files), etc.
replace_ellipsis = True
(own_opts, args) = getopt.getopt(args, 'a:p:o:D:E:f:w:t:',
('depdir=','depfile=','assert-file-list=',
'help',
'output-all-resource-defines',
'no-output-all-resource-defines',
'no-replace-ellipsis',
......@@ -209,6 +210,9 @@ are exported to translation interchange files (e.g. XMB files), etc.
js_minifier = val
elif key == '--whitelist-support':
whitelist_support = True
elif key == '--help':
self.ShowUsage()
sys.exit(0)
if len(args):
print 'This tool takes no tool-specific arguments.'
......
......@@ -7,6 +7,7 @@
import getopt
import os
import sys
from grit import grd_reader
from grit.node import structure
......@@ -32,10 +33,13 @@ The output directory is used for display only.
def Run(self, opts, args):
"""Main method for the buildinfo tool."""
self.output_directory = '.'
(own_opts, args) = getopt.getopt(args, 'o:')
(own_opts, args) = getopt.getopt(args, 'o:', ('help',))
for (key, val) in own_opts:
if key == '-o':
self.output_directory = val
elif key == '--help':
self.ShowUsage()
sys.exit(0)
if len(args) > 0:
print 'This tool takes exactly one argument: the output directory via -o'
return 2
......
......@@ -5,6 +5,7 @@
'''Count number of occurrences of a given message ID.'''
import getopt
import sys
from grit import grd_reader
from grit.tool import interface
......@@ -21,7 +22,11 @@ class CountMessage(interface.Tool):
def ParseOptions(self, args):
"""Set this objects and return all non-option arguments."""
own_opts, args = getopt.getopt(args, '')
own_opts, args = getopt.getopt(args, '', ('help',))
for key, val in own_opts:
if key == '--help':
self.ShowUsage()
sys.exit(0)
return args
def Run(self, opts, args):
......
......@@ -7,6 +7,7 @@
import os
import getopt
import sys
import tempfile
from grit.node import structure
......@@ -48,7 +49,7 @@ class DiffStructures(interface.Tool):
def Run(self, global_opts, args):
(opts, args) = getopt.getopt(args, 's:e:t:',
['left_encoding=', 'right_encoding='])
('help', 'left_encoding=', 'right_encoding='))
for key, val in opts:
if key == '-s':
self.section = val
......@@ -61,6 +62,9 @@ class DiffStructures(interface.Tool):
self.left_encoding = val
elif key == '--right_encoding':
self.right_encoding == val
elif key == '--help':
self.ShowUsage()
sys.exit(0)
if len(args) != 2:
print "Incorrect usage - 'grit help sdiff' for usage details."
......
......@@ -38,6 +38,10 @@ class Tool(object):
def __init__(self):
self.o = None
def ShowUsage(self):
'''Show usage text for this tool.'''
print self.__doc__
def SetOptions(self, opts):
self.o = opts
......
......@@ -6,6 +6,7 @@
'''
import getopt
import sys
from grit.tool import interface
from grit import constants
......@@ -63,7 +64,11 @@ where in the file.'''
def ParseOptions(self, args):
"""Set this objects and return all non-option arguments."""
own_opts, args = getopt.getopt(args, '')
own_opts, args = getopt.getopt(args, '', ('help',))
for key, val in own_opts:
if key == '--help':
self.ShowUsage()
sys.exit(0)
return args
def Run(self, opts, args):
......
......@@ -9,6 +9,7 @@ import os.path
import getopt
import re
import StringIO
import sys
import types
import grit.node.empty
......@@ -156,11 +157,12 @@ C preprocessor on the .rc file or manually edit it before using this tool.
self.pre_process = None
self.post_process = None
def ParseOptions(self, args):
def ParseOptions(self, args, help_func=None):
'''Given a list of arguments, set this object's options and return
all non-option arguments.
'''
(own_opts, args) = getopt.getopt(args, 'e:h:u:n:r', ['pre=', 'post='])
(own_opts, args) = getopt.getopt(args, 'e:h:u:n:r',
('help', 'pre=', 'post='))
for (key, val) in own_opts:
if key == '-e':
self.input_encoding = val
......@@ -176,6 +178,12 @@ C preprocessor on the .rc file or manually edit it before using this tool.
self.pre_process = val
elif key == '--post':
self.post_process = val
elif key == '--help':
if help_func is None:
self.ShowUsage()
else:
help_func()
sys.exit(0)
return args
def Run(self, opts, args):
......
......@@ -7,6 +7,7 @@
import getopt
import os
import sys
from grit import grd_reader
from grit import pseudo
......@@ -193,7 +194,7 @@ near the top of the file, before you open it in Visual Studio.
def Run(self, opts, args):
self.SetOptions(opts)
own_opts, args = getopt.getopt(args, 'l:f:c:D:')
own_opts, args = getopt.getopt(args, 'l:f:c:D:', ('help',))
for key, val in own_opts:
if key == '-l':
self.SetLanguage(val)
......@@ -205,6 +206,9 @@ near the top of the file, before you open it in Visual Studio.
if key == '-D':
name, val = util.ParseDefine(val)
self.defines[name] = val
elif key == '--help':
self.ShowUsage()
sys.exit(0)
res_tree = grd_reader.Parse(opts.input, debug=opts.extra_verbose)
res_tree.OnlyTheseTranslations([self.lang])
......
......@@ -5,6 +5,7 @@
'''The 'grit transl2tc' tool.
'''
import sys
from grit import grd_reader
from grit import util
......@@ -59,7 +60,7 @@ Bulk Translation Upload tool.
if len(args) and args[0] == '-l':
self.limits = util.ReadFile(args[1], util.RAW_TEXT).split('\n')
args = args[2:]
return self.rc2grd.ParseOptions(args)
return self.rc2grd.ParseOptions(args, help_func=self.ShowUsage)
def Run(self, globopt, args):
args = self.Setup(globopt, args)
......
......@@ -5,6 +5,7 @@
'''GRIT tool that runs the unit test suite for GRIT.'''
import getopt
import sys
import unittest
import grit.test_suite_all
......@@ -20,7 +21,11 @@ This happens in the environment that is set up by the basic GRIT runner.'''
def ParseOptions(self, args):
"""Set this objects and return all non-option arguments."""
own_opts, args = getopt.getopt(args, '')
own_opts, args = getopt.getopt(args, '', ('help',))
for key, val in own_opts:
if key == '--help':
self.ShowUsage()
sys.exit(0)
return args
def Run(self, opts, args):
......
......@@ -7,6 +7,7 @@
import getopt
import os
import sys
from xml.sax import saxutils
......@@ -171,7 +172,7 @@ Other options:
limit_file = None
limit_is_grd = False
limit_file_dir = None
own_opts, args = getopt.getopt(args, 'l:D:ih')
own_opts, args = getopt.getopt(args, 'l:D:ih', ('help',))
for key, val in own_opts:
if key == '-l':
limit_file = open(val, 'r')
......@@ -187,6 +188,9 @@ Other options:
elif key == '-E':
(env_name, env_value) = val.split('=', 1)
os.environ[env_name] = env_value
elif key == '--help':
self.ShowUsage()
sys.exit(0)
if not len(args) == 1:
print ('grit xmb takes exactly one argument, the path to the XMB file '
'to output.')
......
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