Skip to content

Commit

Permalink
Default to watching pwd (.), and complain if there's nothing to watch.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewfallshaw committed Oct 24, 2010
1 parent 9b18876 commit 61c6b64
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions lib/tripwire/cli.rb
Expand Up @@ -17,30 +17,55 @@ def initialize(args)
recursive = true
delay = 1
option_parser = OptionParser.new do |opt|
opt.banner = "Usage: tripwire [options] <command> <filespec>+"
opt.on("-e","--exclude <pattern>", String, "a pattern defining files/folders to ignore") do |e|
opt.banner = "Usage: tripwire [options] COMMAND [FILESPEC]+"
opt.on("-e","--exclude PATTERN", String,
"a pattern defining files/folders to ignore") do |e|
scanner.exclude_patterns << e
end
opt.on("-d","--delay <seconds>", Integer, "number of seconds between each scan (defaults to 1)") do |d|
opt.on("-d","--delay SECONDS", Integer,
"number of seconds between each scan (defaults to 1)") do |d|
delay = d
end
opt.on("-q","--quiet", "suppresses output") do
opt.on("-q","--quiet",
"suppresses output") do
scanner.quiet = true
end
opt.on("-n","--non-recursive", "tells tripwire *not* to scan folders recursively") do
opt.on("-n","--non-recursive",
"tells tripwire *not* to scan folders recursively") do
recursive = false
end
end

option_parser.parse!(args)

command = args.shift
args.map!{|arg| File.directory?(arg) ? "#{arg}/**/*" : arg} if recursive
nothing_to_watch = true
args.map! do |arg|
if File.exist?(arg)
nothing_to_watch = false
else
STDERR.puts "'#{arg}' doesn't exist."
end
File.directory?(arg) ? "#{arg}/**/*" : arg
end if recursive

# Enough to run?
if command.nil?
raise "No command specified. Please specify a command to run."
elsif args.empty?
args = ["."]
puts "Watching default path '.'"
elsif nothing_to_watch
STDERR.puts "WARNING: Nothing to watch in '#{args.join(", ")}'"
# else good to run
end

scanner.scan_patterns.concat(args)
runner = Tripwire::Runner.new(scanner, command, :delay => delay)
runner.run! rescue puts "#{$!}\n(type tripwire -h for help)"

runner.run!
rescue
STDERR.puts "#{$!}\n\n#{option_parser}"
end

end
end
end

0 comments on commit 61c6b64

Please sign in to comment.