tools: Refactor full help printing
Collect the code for printing the full help message of patman, buildman and binman into a single function in patman.tools. Signed-off-by: Paul Barker <paul.barker@sancloud.com>
This commit is contained in:
@@ -565,12 +565,9 @@ def Binman(args):
|
|||||||
global state
|
global state
|
||||||
|
|
||||||
if args.full_help:
|
if args.full_help:
|
||||||
pager = os.getenv('PAGER')
|
tools.PrintFullHelp(
|
||||||
if not pager:
|
os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'README.rst')
|
||||||
pager = 'more'
|
)
|
||||||
fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
|
|
||||||
'README.rst')
|
|
||||||
command.Run(pager, fname)
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
# Put these here so that we can import this module without libfdt
|
# Put these here so that we can import this module without libfdt
|
||||||
|
@@ -16,6 +16,7 @@ from patman import command
|
|||||||
from patman import gitutil
|
from patman import gitutil
|
||||||
from patman import patchstream
|
from patman import patchstream
|
||||||
from patman import terminal
|
from patman import terminal
|
||||||
|
from patman import tools
|
||||||
from patman.terminal import Print
|
from patman.terminal import Print
|
||||||
|
|
||||||
def GetPlural(count):
|
def GetPlural(count):
|
||||||
@@ -133,12 +134,9 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None,
|
|||||||
global builder
|
global builder
|
||||||
|
|
||||||
if options.full_help:
|
if options.full_help:
|
||||||
pager = os.getenv('PAGER')
|
tools.PrintFullHelp(
|
||||||
if not pager:
|
os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'README')
|
||||||
pager = 'more'
|
)
|
||||||
fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
|
|
||||||
'README')
|
|
||||||
command.Run(pager, fname)
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
gitutil.Setup()
|
gitutil.Setup()
|
||||||
|
@@ -28,6 +28,7 @@ from patman import settings
|
|||||||
from patman import terminal
|
from patman import terminal
|
||||||
from patman import test_util
|
from patman import test_util
|
||||||
from patman import test_checkpatch
|
from patman import test_checkpatch
|
||||||
|
from patman import tools
|
||||||
|
|
||||||
epilog = '''Create patches from commits in a branch, check them and email them
|
epilog = '''Create patches from commits in a branch, check them and email them
|
||||||
as specified by tags you place in the commits. Use -n to do a dry run first.'''
|
as specified by tags you place in the commits. Use -n to do a dry run first.'''
|
||||||
@@ -170,14 +171,9 @@ elif args.cmd == 'send':
|
|||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
elif args.full_help:
|
elif args.full_help:
|
||||||
pager = os.getenv('PAGER')
|
tools.PrintFullHelp(
|
||||||
if not pager:
|
os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'README')
|
||||||
pager = shutil.which('less')
|
)
|
||||||
if not pager:
|
|
||||||
pager = 'more'
|
|
||||||
fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
|
|
||||||
'README')
|
|
||||||
command.Run(pager, fname)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# If we are not processing tags, no need to warning about bad ones
|
# If we are not processing tags, no need to warning about bad ones
|
||||||
|
@@ -581,3 +581,16 @@ def ToHexSize(val):
|
|||||||
hex value of size, or 'None' if the value is None
|
hex value of size, or 'None' if the value is None
|
||||||
"""
|
"""
|
||||||
return 'None' if val is None else '%#x' % len(val)
|
return 'None' if val is None else '%#x' % len(val)
|
||||||
|
|
||||||
|
def PrintFullHelp(fname):
|
||||||
|
"""Print the full help message for a tool using an appropriate pager.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
fname: Path to a file containing the full help message
|
||||||
|
"""
|
||||||
|
pager = os.getenv('PAGER')
|
||||||
|
if not pager:
|
||||||
|
pager = shutil.which('less')
|
||||||
|
if not pager:
|
||||||
|
pager = 'more'
|
||||||
|
command.Run(pager, fname)
|
||||||
|
Reference in New Issue
Block a user