errbotio / errbot

Errbot is a chatbot, a daemon that connects to your favorite chat service and bring your tools and some fun into the conversation.
http://errbot.io
GNU General Public License v3.0
3.12k stars 614 forks source link

Add method to append argparse option to the Command object. #1394

Closed nzlosh closed 3 years ago

nzlosh commented 4 years ago

When creating a dynamic command plugin that uses the arg_botcmd function, there is no obvious way to pass multiple arguments to the Command object as is the case when using the Decorator pattern with mutiple arguments.

This pull request adds a new method append_args to the Command object which can take arguments and keywords. Below is an example of how this code would be used.

        Help_Command = Command(
            eg_help,
            name="eg_help",
            cmd_type=arg_botcmd,
            cmd_args=("--topic",),
            cmd_kwargs={"dest": "topic", "type": str},
            doc="Provide example help."
        )
        Help_Command.append_args(("--filter",), {"dest": "filter", "type": str})
        Help_Command.append_args(("--limit",), {"dest": "limit", "type": int})
        Help_Command.append_args(("--offset",), {"dest": "offset", "type": int})

        self.create_dynamic_plugin(
            name="Example_Plugin",
            doc="Example.",
            commands=(Help_Command)
nzlosh commented 4 years ago

The test pipeline is failing but it seems to be something unrelated to the code changes I made.

ERROR    errbot.repo_manager:repo_manager.py:167 Could not update from source https://repos.errbot.io/repos.json, keep the index as it is.

repos.errbot.io doesn't resolve from my machine for example.

gbin commented 4 years ago

@nzlosh fixed please retry. Sorry for that.

sijis commented 4 years ago

Rebased to cleanup the PR.

nzlosh commented 4 years ago

Any thoughts on including this PR in the next point release?

sijis commented 4 years ago

Can't see a reason why not.

nzlosh commented 3 years ago

Should I merge master?

sijis commented 3 years ago

@nzlosh This needs a rebase.

nzlosh commented 3 years ago

@sijis There were a few snags rebasing, but everything has been sorted for a merge to master.

nzlosh commented 3 years ago

Will this PR be include for the next release?

sijis commented 3 years ago

I can look to add it