Improved cli error handling

This commit is contained in:
Sven Heidemann 2020-12-16 15:13:18 +01:00
parent acfe158470
commit bbd0a0f4c4
3 changed files with 7 additions and 0 deletions

View File

@ -25,6 +25,7 @@ class CLI:
except Exception as e: except Exception as e:
tb = traceback.format_exc() tb = traceback.format_exc()
Console.error(str(e), tb) Console.error(str(e), tb)
Console.error('Run \'cpl help\'')
def main(): def main():

View File

@ -13,19 +13,23 @@ class New(CommandBase):
rel_path = f'{os.path.dirname(__file__)}/../' rel_path = f'{os.path.dirname(__file__)}/../'
if len(args) == 0: if len(args) == 0:
Console.error(f'Expected arguments {args}') Console.error(f'Expected arguments {args}')
Console.error('Run \'cpl help\'')
return return
elif len(args) != 2: elif len(args) != 2:
Console.error(f'Invalid arguments {args}') Console.error(f'Invalid arguments {args}')
Console.error('Run \'cpl help\'')
return return
if not os.path.isdir(f'{rel_path}/templates/{args[0]}'): if not os.path.isdir(f'{rel_path}/templates/{args[0]}'):
Console.error(f'Unexpected argument {args[0]}') Console.error(f'Unexpected argument {args[0]}')
Console.error('Run \'cpl help\'')
sub_args = args[1:] sub_args = args[1:]
if len(sub_args) != 1: if len(sub_args) != 1:
Console.error(f'Unexpected argument {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('/')): if not (sub_args[0].startswith('.') or sub_args[0].startswith('/')):
full_path = f'./{sub_args[0]}' full_path = f'./{sub_args[0]}'

View File

@ -24,5 +24,7 @@ class Interpreter:
cmd.run(args) cmd.run(args)
else: else:
Console.error(f'Unexpected command {command}') Console.error(f'Unexpected command {command}')
Console.error('Run \'cpl help\'')
else: else:
Console.error(f'Unexpected command {command}') Console.error(f'Unexpected command {command}')
Console.error('Run \'cpl help\'')