Command with a default arg fails to run when omitting the argument
In order to let us help you better, please fill out the following fields as best you can:
I am...
- [x] Reporting a bug
- [ ] Suggesting a new feature
- [ ] Requesting help with running my bot
- [ ] Requesting help writing plugins
- [ ] Here about something else
I am running...
- Errbot version: 6.1.6
- OS version: ubuntu 18.04
- Python version: 3.6.9
- Using a virtual environment: docker
- Backend: slack
Issue description
I have a command with an argument. I'd like it to work with a default value if the argument is omitted.
@arg_botcmd("service_name", type=str, default="myservice", help="Service name")
def getstatus(self, msg, service_name):
...
I get an error when I try to run it w/o an argument.
User: !getstatus myservice
Errbot: ok
User: !getstatus
Errbot: I couldn't parse the arguments; the following arguments are required: service_name
The correct/expected result would be for the command to pick the default value myservice for the missing argument service_name. I also tried to use a default arg value in the method signature, but it did not help.
def getstatus(self, msg, service_name="myservice"):
As how the arg_botcmd is working now, first argument creates the ArgumentParser object, and does not allow setting the required flag you're looking for. https://docs.python.org/3/library/argparse.html#required
https://github.com/errbotio/errbot/blob/54542fd38250b4cb977283854c5cb2b446b1281b/errbot/init.py#L383-L386
But the next ones can use the argparse options. https://github.com/errbotio/errbot/blob/54542fd38250b4cb977283854c5cb2b446b1281b/errbot/init.py#L445