Created
October 14, 2013 06:17
-
-
Save zbal/6971545 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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