Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command with a default arg fails to run when omitting the argument #1483

Open
1 of 5 tasks
alpinweis opened this issue Dec 1, 2020 · 1 comment
Open
1 of 5 tasks

Comments

@alpinweis
Copy link

In order to let us help you better, please fill out the following fields as best you can:

I am...

  • 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"):
@duhow
Copy link
Contributor

duhow commented Dec 9, 2020

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

errbot/errbot/__init__.py

Lines 383 to 386 in 54542fd

err_command_parser = ArgumentParser(
prog=name or func.__name__,
description=func.__doc__,
)

But the next ones can use the argparse options.

wrapper._err_command_parser.add_argument(*argparse_args, **kwargs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants