Skip to content

Commit

Permalink
- Fix potentially faulty arg parsing
Browse files Browse the repository at this point in the history
- Make multi args command work again, it wasn't
- Make %f useful if embedded in an arg
  • Loading branch information
mathieu longtin committed Feb 25, 2015
1 parent 5a605c6 commit fa08b6b
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions whenchanged/whenchanged.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ def run_command(self, thefile):
return
new_command = []
for item in self.command:
if item == "%f":
item = thefile
new_command.append(item)
subprocess.call(new_command, shell=True)
new_command.append(item.replace('%f', thefile))
subprocess.call(new_command, shell=(len(new_command) == 1))
self.last_run = time.time()

def is_interested(self, path):
Expand Down Expand Up @@ -127,23 +125,24 @@ def main():
verbose = False
run_once = False

flags = []
while args[0][0] == '-' and args[0] != '-c':
flags.append(args.pop(0))

if '-v' in flags:
verbose = True

if '-r' in flags:
recursive = True

if '-1' in flags:
run_once = True
while args and args[0][0] == '-':
flag = args.pop(0)
if flag == '-v':
verbose = True
elif flag == '-r':
recursive = True
elif flag == '-1':
run_once = True
elif flag == '-c':
command = args
args = []
else:
break

if '-c' in args:
cpos = args.index('-c')
files = args[:cpos]
command = args[cpos+1:]
command = args[cpos + 1:]
elif len(args) >= 2:
files = [args[0]]
command = args[1:]
Expand Down

0 comments on commit fa08b6b

Please sign in to comment.