From 905558da45859f2d0a344d666042c8b0e93f9d50 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 6 Sep 2011 09:30:12 -0400 Subject: [PATCH] check instead to see if stdin is not a tty for triggering pipe --- bin/whenever | 3 --- lib/whenever/command_line.rb | 6 +++--- test/functional/command_line_test.rb | 4 +++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/bin/whenever b/bin/whenever index bfb43f6..c2bd54c 100755 --- a/bin/whenever +++ b/bin/whenever @@ -33,9 +33,6 @@ OptionParser.new do |opts| opts.on('-k', '--cut [lines]', 'Cut lines from the top of the cronfile') do |lines| options[:cut] = lines.to_i if lines end - opts.on('-p', '--pipe', 'Pipe crontab from stdin, through whenever, and out to stdout') do - options[:pipe] = true - end opts.on('-v', '--version') { puts "Whenever v#{Whenever::VERSION}"; exit(0) } end.parse! diff --git a/lib/whenever/command_line.rb b/lib/whenever/command_line.rb index 07dfca7..fc1eb39 100644 --- a/lib/whenever/command_line.rb +++ b/lib/whenever/command_line.rb @@ -59,7 +59,7 @@ module Whenever return @current_crontab if @current_crontab command_results = ( - if @options[:pipe] + if !stdin.tty? stdin.read else command = ['crontab -l'] @@ -76,7 +76,7 @@ module Whenever def write_crontab(contents) target_fh = ( - if @options[:pipe] + if !stdin.tty? stdout else File.open(Tempfile.new('whenever_tmp_cron').path, File::WRONLY | File::APPEND) @@ -86,7 +86,7 @@ module Whenever target_fh << contents target_fh.close - if @options[:pipe] + if !stdin.tty? exit(0) else command = ['crontab'] diff --git a/test/functional/command_line_test.rb b/test/functional/command_line_test.rb index ed75d60..2c88321 100644 --- a/test/functional/command_line_test.rb +++ b/test/functional/command_line_test.rb @@ -331,8 +331,10 @@ EXISTING_CRON @mock_stdout = StringIO.new + @mock_stdin.stubs(:tty?).returns(false) + File.expects(:exists?).with('config/schedule.rb').returns(true) - @command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier', :pipe => true) + @command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier') @task = "#{two_hours} /my/command" Whenever.expects(:cron).returns(@task)