From bbd0a0f4c4d61f732091d0431f378b82e0476985 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 16 Dec 2020 15:13:18 +0100 Subject: [PATCH] Improved cli error handling --- src/sh_edraft/cli/cpl_cli/cli.py | 1 + src/sh_edraft/cli/cpl_cli/commands/new.py | 4 ++++ src/sh_edraft/cli/interpreter/interpreter.py | 2 ++ 3 files changed, 7 insertions(+) diff --git a/src/sh_edraft/cli/cpl_cli/cli.py b/src/sh_edraft/cli/cpl_cli/cli.py index d74f807b..ae63de86 100644 --- a/src/sh_edraft/cli/cpl_cli/cli.py +++ b/src/sh_edraft/cli/cpl_cli/cli.py @@ -25,6 +25,7 @@ class CLI: except Exception as e: tb = traceback.format_exc() Console.error(str(e), tb) + Console.error('Run \'cpl help\'') def main(): diff --git a/src/sh_edraft/cli/cpl_cli/commands/new.py b/src/sh_edraft/cli/cpl_cli/commands/new.py index c9d63353..90ebb690 100644 --- a/src/sh_edraft/cli/cpl_cli/commands/new.py +++ b/src/sh_edraft/cli/cpl_cli/commands/new.py @@ -13,19 +13,23 @@ class New(CommandBase): rel_path = f'{os.path.dirname(__file__)}/../' if len(args) == 0: Console.error(f'Expected arguments {args}') + Console.error('Run \'cpl help\'') return elif len(args) != 2: Console.error(f'Invalid arguments {args}') + Console.error('Run \'cpl help\'') return if not os.path.isdir(f'{rel_path}/templates/{args[0]}'): Console.error(f'Unexpected argument {args[0]}') + Console.error('Run \'cpl help\'') sub_args = args[1:] if len(sub_args) != 1: Console.error(f'Unexpected argument {sub_args[1]}') + Console.error('Run \'cpl help\'') if not (sub_args[0].startswith('.') or sub_args[0].startswith('/')): full_path = f'./{sub_args[0]}' diff --git a/src/sh_edraft/cli/interpreter/interpreter.py b/src/sh_edraft/cli/interpreter/interpreter.py index 5a7f38d8..577989d8 100644 --- a/src/sh_edraft/cli/interpreter/interpreter.py +++ b/src/sh_edraft/cli/interpreter/interpreter.py @@ -24,5 +24,7 @@ class Interpreter: cmd.run(args) else: Console.error(f'Unexpected command {command}') + Console.error('Run \'cpl help\'') else: Console.error(f'Unexpected command {command}') + Console.error('Run \'cpl help\'')