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:
tb = traceback.format_exc()
Console.error(str(e), tb)
Console.error('Run \'cpl help\'')
def main():

View File

@ -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]}'

View File

@ -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\'')