cli help rework and cleanup

Fixes several typos, expands help for positional arguments,
prints out default values of optional arguments
and changes help formatter to allow more control over output.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: I0182127fb11cdc49cc82e05367f272ee813d2647
This commit is contained in:
Jiri Podivin 2021-02-23 16:55:29 +01:00
parent 3a7207f10d
commit 3b06d8868a

View File

@ -47,6 +47,16 @@ class _CommaListAction(argparse.Action):
setattr(namespace, self.dest, values.split(','))
class ValidationsFormatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawTextHelpFormatter):
"""
Composite class inheriting from both ArgumentDefaultsHelpFormatter
and RawTextHelpFormatter.
Thus allowing for both more precise help output management
and automatic printing of default arg values.
"""
pass
class Validation(argparse.ArgumentParser):
"""Validation client implementation class"""
@ -54,17 +64,29 @@ class Validation(argparse.ArgumentParser):
def __init__(self, description=DESCRIPTION, epilog=EPILOG):
"""Init validation paser"""
super(Validation, self).__init__(description=DESCRIPTION,
epilog=EPILOG)
super(Validation, self).__init__(
description=DESCRIPTION,
epilog=EPILOG,
formatter_class=ValidationsFormatter)
def parser(self, parser):
"""Argument parser for validation"""
parser.add_argument('action',
choices=['run', 'list', 'show'],
help='Validation Action')
help=(
'Validation Action: \n'
' run:\n launches validations specified by '
'the --group or --validation args. \n'
' list:\n prints list of available validations,'
'including their groups. \n'
' show:\n prints list of validations executions and related info.'
))
parser.add_argument('--inventory', '-i', type=str,
default="localhost",
help="Path of the Ansible inventory.")
help=(
"Either a path of the Ansible inventory file, \n"
"or a comma-separated list of hosts. \n"
))
parser.add_argument('--extra-vars', action='store',
nargs='+',
help="Extra ansible variables")
@ -73,33 +95,34 @@ class Validation(argparse.ArgumentParser):
dest="validation_name",
action=_CommaListAction,
default=[],
help=("Run specific validations, "
"if more than one validation is required "
"separate the names with commas: "
"--validation check-ftype,512e | "
"--validation 512e"))
help=("Run specific validations, \n"
"if more than one validation is required \n"
"separate the names with commas: \n"
"--validation check-ftype,512e | \n"
"--validation 512e \n"))
parser.add_argument('--group', '-g',
metavar='<group>[,<group>,...]',
action=_CommaListGroupAction,
default=[],
help=("Run specific group validations, "
"if more than one group is required "
"separate the group names with commas: "
"--group pre-upgrade,prep | "
"--group openshift-on-openstack"))
help=("Run specific group of validations, \n"
"if more than one group is required \n"
"separate the group names with commas: \n"
"--group pre-upgrade,prep | \n"
"--group openshift-on-openstack \n"))
parser.add_argument('--quiet', action='store_true',
help=("Run Ansible in silent mode."))
help=("Run Ansible in silent mode. \n"))
parser.add_argument('--validation-dir', dest='validation_dir',
default=constants.ANSIBLE_VALIDATION_DIR,
help=("Path where the validation playbooks "
"is located."))
"are located. \n"))
parser.add_argument('--ansible-base-dir', dest='ansible_base_dir',
default=constants.DEFAULT_VALIDATIONS_BASEDIR,
help=("Path where the ansible roles, library "
"and plugins is located."))
help=("Path where the ansible roles, library \n"
"and plugins are located. \n"))
parser.add_argument('--output-log', dest='output_log',
default=None,
help=("Path where the run result will be stored"))
help=("Path where the run result will be stored. \n"))
return parser.parse_args()
def _print_dict_table(self, data):