Skip to content

Commit

Permalink
parser: Keep track of the number of processed arguments even when fai…
Browse files Browse the repository at this point in the history
…ling

This will enable providing nicer error messages to user.
eras committed Mar 26, 2022
1 parent 637bc93 commit 7e923a9
Showing 3 changed files with 120 additions and 100 deletions.
4 changes: 2 additions & 2 deletions teslabot/commands.py
Original file line number Diff line number Diff line change
@@ -87,14 +87,14 @@ def __init__(self, commands: "Commands[Context]") -> None:

def parse(self, args: List[str]) -> ParseResult[Callable[[Context], Awaitable[None]]]:
if len(args) == 0:
return ParseFail("No command name")
return ParseFail("No command name", processed=0)
invocation = Invocation(args[0], args[1:])
if self.commands.has_command(invocation.name):
async def invoke(context: Context) -> None:
await self.commands.invoke(context, invocation)
return ParseOK(invoke, processed=len(args))
else:
return ParseFail(f"No such command: {invocation.name}")
return ParseFail(f"No such command: {invocation.name}", processed=0)

class Commands(Generic[Context]):
_commands: List[Command[Context]]
Loading

0 comments on commit 7e923a9

Please sign in to comment.