Skip to content

Commit

Permalink
Merge pull request joh#27 from tessus/master
Browse files Browse the repository at this point in the history
hide output unless verbose option (-v) is used
  • Loading branch information
joh committed Nov 22, 2014
2 parents 05f601a + 65b8f8f commit 23c5606
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions whenchanged/whenchanged.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
"""%(prog)s - run a command when a file is changed
Usage: %(prog)s [-r] FILE COMMAND...
%(prog)s [-r] FILE [FILE ...] -c COMMAND
Usage: %(prog)s [-v] [-r] FILE COMMAND...
%(prog)s [-v] [-r] FILE [FILE ...] -c COMMAND
FILE can be a directory. Watch recursively with -r.
Verbose output with -v.
Use %%f to pass the filename to the command.
Copyright (c) 2011, Johannes H. Jensen.
Expand Down Expand Up @@ -117,10 +118,15 @@ def main():
files = []
command = []
recursive = False
verbose = False

if args and args[0] == '-r':
if '-v' in args:
verbose = True
args.remove('-v')

if '-r' in args:
recursive = True
args.pop(0)
args.remove('-r')

if '-c' in args:
cpos = args.index('-c')
Expand All @@ -140,9 +146,11 @@ def main():
if len(files) > 1:
l = ["'%s'" % f for f in files]
s = ', '.join(l[:-1]) + ' or ' + l[-1]
print("When %s changes, run '%s'" % (s, print_command))
if verbose:
print("When %s changes, run '%s'" % (s, print_command))
else:
print("When '%s' changes, run '%s'" % (files[0], print_command))
if verbose:
print("When '%s' changes, run '%s'" % (files[0], print_command))

wc = WhenChanged(files, command, recursive)
try:
Expand Down

0 comments on commit 23c5606

Please sign in to comment.