Commits

Bruno Bord committed db55199

dynamic loading

Comments (0)

Files changed (1)

         self.config = Config()
 
     def run(self):
-        # TODO: refactor that to make it dynamic
-        if self.command_name == 'add':
-            from llog.commands.add import Command
-        elif self.command_name == 'review':
-            from llog.commands.review import Command
-        command = Command(sys.argv[2:], usage())
+        "loads the command module and run it"
+        # dynamically import command module
+        command_module = __import__('llog.commands.%s' % sys.argv[1], fromlist=['llog.commands'])
+        command = command_module.Command(sys.argv[2:], usage())
+        # actually run the command
         command.run(self.config.path)