-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Use argparse to parse !command arguments? #30
Comments
I love the functionality this will bring, but I worry it takes away the ability to make plugins really simple. I am going to think about ways to abstract this. |
You could set add_arguments in BasePlugin to have the following default: def add_arguments(self, parser):
parser.add_argument('args', nargs='*') Then it becomes possible to have the following plugin: import pinhook.plugin
class HelloPlugin(pinhook.plugin.BasePlugin):
help = 'Say hello to the world!'
def handle(self, msg, args=['world']):
return pinhook.plugin.message('Hello {} !'.format(', '.join(args))) |
I literally just came up with a way to do this. Bad pseudocode to follow. @pinhook.plugin.register('thing')
@pinhook.plugin.add_argument(args*, kwargs**)
def thing(msg):
return "pants" basically this would run through and create an argument parser for the plugin object, and |
Of course, thinking about this more, I am not sure how those decorators stack 🤔 |
When creating command-line scripts, the cool way to parse command-line arguments is to use the
argparse
module. That could automatically generate help text (like for #19) with details about arguments. This should be easy to do with class-based plugins (#27) by using a way similar to how Django commands are designed:The text was updated successfully, but these errors were encountered: