bbinet avatar bbinet committed 86d7ebe

add --with-arguments option for passing args to command run

Comments (0)

Files changed (1)

 class Runner(object):
     """Responsible for running a specified command upon file changes."""
 
-    def __init__(self, reporter, change_monitor, ignore_events, no_initial_run, command):
+    def __init__(self, reporter, change_monitor, ignore_events, no_initial_run, with_arguments, command):
         """Creates a new command runner."""
 
         self.reporter = reporter
         self.change_monitor = change_monitor
         self.ignore_events = ignore_events
         self.no_initial_run = no_initial_run
+        self.with_arguments = with_arguments
         self.command = []
         for part in command:
             self.command.extend(part.split())
     def do_command(self, change_set):
         """Invoke our command."""
 
-        subprocess.call(self.command + list(change_set))
+        subprocess.call(self.command + (list(change_set) if self.with_arguments else []))
 
     def do_run(self, change_set):
         """Perform a command run."""
                           help='''don't add the following to the black list: %s''' % ' '.join(BUILTIN_BLACK_LIST))
         parser.add_option('-r', '--no-initial-run', action='store_true', default=False,
                           help='''don't perform an initial run of the command, instead start monitoring and wait for changes''')
+        parser.add_option('-a', '--with-arguments', action='store_true', default=False,
+                          help='''wether to pass the updated file path as an argument to the command run''')
 
         options, command = parser.parse_args()
 
         if not options.no_default_black_list:
             black_list.extend(BUILTIN_BLACK_LIST)
         no_initial_run = options.no_initial_run
+        with_arguments = options.with_arguments
 
         # Create the reporter that prints info to the terminal.
         with Reporter() as reporter:
 
             # Create the runner that invokes the command on file
             # changes.
-            runner = Runner(reporter, change_monitor, ignore_events, no_initial_run, command)
+            runner = Runner(reporter, change_monitor, ignore_events, no_initial_run, with_arguments, command)
 
             # Enter the main loop until we break out.
             runner.main_loop()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.