Added a new method do_run and improved error messages.

This commit is contained in:
Paul Gauthier 2023-05-10 11:15:20 -07:00
parent 8b2fdd4b92
commit 126b5e1f3b

View file

@ -13,18 +13,24 @@ class Commands:
return commands
def do_run(self, cmd_name, args):
pass
def run(self, inp, console):
words = inp.strip().split()
if not words:
return
first_word = words[0]
rest_inp = inp[len(words[0]):]
all_commands = self.get_commands()
matching_commands = [cmd for cmd in all_commands if cmd.startswith(first_word)]
if len(matching_commands) == 1:
console.print('[green]run', matching_commands[0])
self.do_run(matching_commands[0][1:], rest_inp)
elif len(matching_commands) > 1:
console.print('[yellow]Partial matches:', ', '.join(matching_commands))
console.print('[red]Ambiguous command:', ', '.join(matching_commands))
else:
console.print('[red]Error: Command not found')
console.print(f'[red]Error: {first_word} is not a valid command.')