Fixed help appearance on empty/unknown commands
Change-Id: I709e05b3c2658da7a8b257e2970f5f4da2e05cf2
Related-PROD: PROD-35610
diff --git a/cfg_checker/cli/command.py b/cfg_checker/cli/command.py
index 0a892d8..f98e608 100644
--- a/cfg_checker/cli/command.py
+++ b/cfg_checker/cli/command.py
@@ -12,6 +12,7 @@
mods_prefix = mods_import_path + '.'
commands = {}
+parsers_inits = {}
parsers = {}
helps = {}
# Pure dynamic magic, loading all 'do_*' methods from available modules
@@ -26,21 +27,24 @@
# A package! Create it and add commands
commands[mod_name] = \
[_n[3:] for _n in dir(_p) if _n.startswith("do_")]
- parsers[mod_name] = getattr(_p, 'init_parser')
+ parsers_inits[mod_name] = getattr(_p, 'init_parser')
+ parsers[mod_name] = {}
helps[mod_name] = getattr(_p, 'command_help')
def execute_command(args, command):
# Validate the commands
# check commands
+ if command not in commands:
+
+ logger_cli.info("\n# Please, type a command listed above")
+ return 1
if not hasattr(args, 'type') or not args.type:
+ parsers[command].print_help()
logger_cli.info("\n# Please, type a command listed above")
return 1
_type = args.type.replace("-", "_") if "-" in args.type else args.type
- if command not in commands:
- logger_cli.info("\n# Please, type a command listed above")
- return 1
- elif _type not in commands[command]:
+ if _type not in commands[command]:
# check type
logger_cli.info(
"\n# Please, select '{}' command type listed above".format(
@@ -79,7 +83,7 @@
def cli_command(_title, _name):
my_parser = MyParser(_title)
- parsers[_name](my_parser)
+ parsers[_name] = parsers_inits[_name](my_parser)
# parse arguments
try: