Added logic to cli to use --help option for help command

This commit is contained in:
Sven Heidemann 2021-04-12 19:43:55 +02:00
parent d94b25d9d8
commit 696c62292b
2 changed files with 19 additions and 3 deletions

View File

@ -30,6 +30,7 @@ class CLI(ApplicationABC):
ApplicationABC.__init__(self, config, services) ApplicationABC.__init__(self, config, services)
self._command_handler: Optional[CommandHandler] = None self._command_handler: Optional[CommandHandler] = None
self._options: list[str] = []
def configure(self): def configure(self):
self._command_handler: CommandHandler = self._services.get_service(CommandHandler) self._command_handler: CommandHandler = self._services.get_service(CommandHandler)
@ -47,6 +48,9 @@ class CLI(ApplicationABC):
self._command_handler.add_command(CommandModel('update', ['u', 'U'], UpdateService, False, True, True)) self._command_handler.add_command(CommandModel('update', ['u', 'U'], UpdateService, False, True, True))
self._command_handler.add_command(CommandModel('version', ['v', 'V'], VersionService, False, False, False)) self._command_handler.add_command(CommandModel('version', ['v', 'V'], VersionService, False, False, False))
self._command_handler.add_command(CommandModel('--help', ['-h', '-H'], HelpService, False, False, False))
self._options.append('--help')
def main(self): def main(self):
""" """
Entry point of the CPL CLI Entry point of the CPL CLI
@ -56,9 +60,18 @@ class CLI(ApplicationABC):
command = None command = None
args = [] args = []
if len(self._configuration.additional_arguments) > 0: if len(self._configuration.additional_arguments) > 0:
command = self._configuration.additional_arguments[0] is_option = False
if len(self._configuration.additional_arguments) > 1: for opt in self._options:
args = self._configuration.additional_arguments[1:] if opt in self._configuration.additional_arguments:
is_option = True
command = opt
args = self._configuration.additional_arguments
args.remove(opt)
if not is_option:
command = self._configuration.additional_arguments[0]
if len(self._configuration.additional_arguments) > 1:
args = self._configuration.additional_arguments[1:]
else: else:
for cmd in self._command_handler.commands: for cmd in self._command_handler.commands:
result = self._configuration.get_configuration(cmd.name) result = self._configuration.get_configuration(cmd.name)

View File

@ -69,6 +69,9 @@ class Startup(StartupABC):
self._configuration.add_console_argument(ConsoleArgument('', 'uninstall', ['ui', 'UI'], ' ')) self._configuration.add_console_argument(ConsoleArgument('', 'uninstall', ['ui', 'UI'], ' '))
self._configuration.add_console_argument(ConsoleArgument('', 'update', ['u', 'U'], '')) self._configuration.add_console_argument(ConsoleArgument('', 'update', ['u', 'U'], ''))
self._configuration.add_console_argument(ConsoleArgument('', 'version', ['v', 'V'], '')) self._configuration.add_console_argument(ConsoleArgument('', 'version', ['v', 'V'], ''))
self._configuration.add_console_argument(ConsoleArgument('', '--help', ['-h', '-H'], ''))
self._configuration.add_console_arguments(error=False) self._configuration.add_console_arguments(error=False)
return self._configuration return self._configuration