check instead to see if stdin is not a tty for triggering pipe
This commit is contained in:
parent
919dbe09ef
commit
905558da45
@ -33,9 +33,6 @@ OptionParser.new do |opts|
|
|||||||
opts.on('-k', '--cut [lines]', 'Cut lines from the top of the cronfile') do |lines|
|
opts.on('-k', '--cut [lines]', 'Cut lines from the top of the cronfile') do |lines|
|
||||||
options[:cut] = lines.to_i if lines
|
options[:cut] = lines.to_i if lines
|
||||||
end
|
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) }
|
opts.on('-v', '--version') { puts "Whenever v#{Whenever::VERSION}"; exit(0) }
|
||||||
end.parse!
|
end.parse!
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ module Whenever
|
|||||||
return @current_crontab if @current_crontab
|
return @current_crontab if @current_crontab
|
||||||
|
|
||||||
command_results = (
|
command_results = (
|
||||||
if @options[:pipe]
|
if !stdin.tty?
|
||||||
stdin.read
|
stdin.read
|
||||||
else
|
else
|
||||||
command = ['crontab -l']
|
command = ['crontab -l']
|
||||||
@ -76,7 +76,7 @@ module Whenever
|
|||||||
|
|
||||||
def write_crontab(contents)
|
def write_crontab(contents)
|
||||||
target_fh = (
|
target_fh = (
|
||||||
if @options[:pipe]
|
if !stdin.tty?
|
||||||
stdout
|
stdout
|
||||||
else
|
else
|
||||||
File.open(Tempfile.new('whenever_tmp_cron').path, File::WRONLY | File::APPEND)
|
File.open(Tempfile.new('whenever_tmp_cron').path, File::WRONLY | File::APPEND)
|
||||||
@ -86,7 +86,7 @@ module Whenever
|
|||||||
target_fh << contents
|
target_fh << contents
|
||||||
target_fh.close
|
target_fh.close
|
||||||
|
|
||||||
if @options[:pipe]
|
if !stdin.tty?
|
||||||
exit(0)
|
exit(0)
|
||||||
else
|
else
|
||||||
command = ['crontab']
|
command = ['crontab']
|
||||||
|
@ -331,8 +331,10 @@ EXISTING_CRON
|
|||||||
|
|
||||||
@mock_stdout = StringIO.new
|
@mock_stdout = StringIO.new
|
||||||
|
|
||||||
|
@mock_stdin.stubs(:tty?).returns(false)
|
||||||
|
|
||||||
File.expects(:exists?).with('config/schedule.rb').returns(true)
|
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"
|
@task = "#{two_hours} /my/command"
|
||||||
Whenever.expects(:cron).returns(@task)
|
Whenever.expects(:cron).returns(@task)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user