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 plugins with sub commands #80

Open
shaunduncan opened this issue Apr 5, 2014 · 1 comment
Open

Command plugins with sub commands #80

shaunduncan opened this issue Apr 5, 2014 · 1 comment
Milestone

Comments

@shaunduncan
Copy link
Owner

A lot of times a single command plugin actually responds to several sub commands. Right now it's kind of a pain to deal with this, because it means you have to physically check first value of args. For example:

@command('foo')
def foo(client, channel, nick, message, cmd, args):
    if args[0] == 'bar':
        # Do the "helga foo bar" sub command
    elif args[0] == 'baz':
        # Do the "helga foo baz" sub command
@shaunduncan shaunduncan added this to the v2 milestone Apr 5, 2014
@shaunduncan
Copy link
Owner Author

A thought on how this should work. Based on this example:

@command('foo')
def foo(client, channel, nick, message, cmd, args):
    if args[0] == 'bar':
        # Do the "helga foo bar" sub command
    elif args[0] == 'baz':
        # Do the "helga foo baz" sub command

This might work:

@command('abc')
@command('foo')
def foo_cmd(client, channel, nick, message, cmd, args):
    # This is run if no sub command match

@foo_cmd.foo.subcommand('bar')
def bar(client, channel, nick, message, cmd, args):
    # this would run on 'helga foo bar'

@foo_cmd.abc.subcommand('xyz')
def xyz(client, channel, nick, message, cmd, args):
    # this would run on 'helga abc xyz'

Or this:

@command('abc')
@command('foo')
def foo_cmd(client, channel, nick, message, cmd, args):
    # This is run if no sub command match

@foo_cmd.foo.bar
def bar(client, channel, nick, message, cmd, args):
    # this would run on 'helga foo bar'

@foo_cmd.abc.xyz
def xyz(client, channel, nick, message, cmd, args):
    # this would run on 'helga abc xyz'

I'm not sure if it should only be a single level of sub commands, or if unlimited levels should be supported.

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

1 participant