Skip to content

Instantly share code, notes, and snippets.

@zbal
Created October 14, 2013 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zbal/6971545 to your computer and use it in GitHub Desktop.
Save zbal/6971545 to your computer and use it in GitHub Desktop.
Option 1 - using a class:
def run(env, command, args):
plugin = Plugin(env)
# Check if the command is defined in the plugin
if 'do_'+ command not in dir(plugin):
return False
# Call function
getattr(plugin, 'do_'+ command)(args)
class Plugin(object):
"""docstring for Plugin"""
def __init__(self, env):
super(Plugin, self).__init__()
self.env = env
def do_cd(self, args):
'''
Command: cd - change directory
'''
print "do cd"
Option 2: without a class ---- incomplete
def run(env, command, args):
plugin = Plugin(env)
# Check if the command is defined in the plugin
if 'do_'+ command not in dir(plugin):
return False
# Call function
getattr(plugin, 'do_'+ command)(args)
def do_cd(env, args):
'''
Command: cd - change directory
'''
print "do cd"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment