fix: raise ValueError if arg is required but empty string. fixes #154 and #216

This commit is contained in:
ikkemaniac 2025-01-05 18:42:29 +01:00
parent c3458eab58
commit b19a2ea487

View file

@ -173,7 +173,7 @@ class CommandHandler:
remaining_val, call_args[arg.name] = arg.match( remaining_val, call_args[arg.name] = arg.match(
remaining_val.strip(), evt=evt, instance=self.__bound_instance__ remaining_val.strip(), evt=evt, instance=self.__bound_instance__
) )
if arg.required and call_args[arg.name] is None: if arg.required and (call_args[arg.name] is None or call_args[arg.name] == ""):
raise ValueError("Argument required") raise ValueError("Argument required")
except ArgumentSyntaxError as e: except ArgumentSyntaxError as e:
await evt.reply(e.message + (f"\n{self.__mb_usage__}" if e.show_usage else "")) await evt.reply(e.message + (f"\n{self.__mb_usage__}" if e.show_usage else ""))