Merge "cli help rework and cleanup"

This commit is contained in:
Zuul 2021-03-03 12:47:48 +00:00 committed by Gerrit Code Review
commit 5ba078c5e1
1 changed files with 42 additions and 19 deletions

View File

@ -47,6 +47,16 @@ class _CommaListAction(argparse.Action):
setattr(namespace, self.dest, values.split(',')) 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): class Validation(argparse.ArgumentParser):
"""Validation client implementation class""" """Validation client implementation class"""
@ -54,17 +64,29 @@ class Validation(argparse.ArgumentParser):
def __init__(self, description=DESCRIPTION, epilog=EPILOG): def __init__(self, description=DESCRIPTION, epilog=EPILOG):
"""Init validation paser""" """Init validation paser"""
super(Validation, self).__init__(description=DESCRIPTION, super(Validation, self).__init__(
epilog=EPILOG) description=DESCRIPTION,
epilog=EPILOG,
formatter_class=ValidationsFormatter)
def parser(self, parser): def parser(self, parser):
"""Argument parser for validation""" """Argument parser for validation"""
parser.add_argument('action', parser.add_argument('action',
choices=['run', 'list', 'show'], 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, parser.add_argument('--inventory', '-i', type=str,
default="localhost", 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', parser.add_argument('--extra-vars', action='store',
nargs='+', nargs='+',
help="Extra ansible variables") help="Extra ansible variables")
@ -73,33 +95,34 @@ class Validation(argparse.ArgumentParser):
dest="validation_name", dest="validation_name",
action=_CommaListAction, action=_CommaListAction,
default=[], default=[],
help=("Run specific validations, " help=("Run specific validations, \n"
"if more than one validation is required " "if more than one validation is required \n"
"separate the names with commas: " "separate the names with commas: \n"
"--validation check-ftype,512e | " "--validation check-ftype,512e | \n"
"--validation 512e")) "--validation 512e \n"))
parser.add_argument('--group', '-g', parser.add_argument('--group', '-g',
metavar='<group>[,<group>,...]', metavar='<group>[,<group>,...]',
action=_CommaListGroupAction, action=_CommaListGroupAction,
default=[], default=[],
help=("Run specific group validations, " help=("Run specific group of validations, \n"
"if more than one group is required " "if more than one group is required \n"
"separate the group names with commas: " "separate the group names with commas: \n"
"--group pre-upgrade,prep | " "--group pre-upgrade,prep | \n"
"--group openshift-on-openstack")) "--group openshift-on-openstack \n"))
parser.add_argument('--quiet', action='store_true', 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', parser.add_argument('--validation-dir', dest='validation_dir',
default=constants.ANSIBLE_VALIDATION_DIR, default=constants.ANSIBLE_VALIDATION_DIR,
help=("Path where the validation playbooks " help=("Path where the validation playbooks "
"is located.")) "are located. \n"))
parser.add_argument('--ansible-base-dir', dest='ansible_base_dir', parser.add_argument('--ansible-base-dir', dest='ansible_base_dir',
default=constants.DEFAULT_VALIDATIONS_BASEDIR, default=constants.DEFAULT_VALIDATIONS_BASEDIR,
help=("Path where the ansible roles, library " help=("Path where the ansible roles, library \n"
"and plugins is located.")) "and plugins are located. \n"))
parser.add_argument('--output-log', dest='output_log', parser.add_argument('--output-log', dest='output_log',
default=None, 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() return parser.parse_args()
def _print_dict_table(self, data): def _print_dict_table(self, data):