check instead to see if stdin is not a tty for triggering pipe

This commit is contained in:
John Bintz 2011-09-06 09:30:12 -04:00
parent 919dbe09ef
commit 905558da45
3 changed files with 6 additions and 7 deletions

View File

@ -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!

View File

@ -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']

View File

@ -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)