Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option to clear all releases from crontab #613

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bin/whenever
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ OptionParser.new do |opts|
options[:clear] = true
options[:identifier] = identifier if identifier
end
opts.on('-p', '--purge') do |identifier|
options[:clear_all] = true
end
opts.on('-s', '--set [variables]', 'Example: --set \'environment=staging&path=/my/sweet/path\'') do |set|
options[:set] = set if set
end
Expand Down
14 changes: 12 additions & 2 deletions lib/whenever/command_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def initialize(options={})
exit(1)
end

if [@options[:update], @options[:write], @options[:clear]].compact.length > 1
warn("[fail] Can only update, write or clear. Choose one.")
if [@options[:update], @options[:write], @options[:clear], options[:clear_all]].compact.length > 1
warn("[fail] Can only update, write, clear or clear_all. Choose one.")
exit(1)
end

Expand All @@ -33,6 +33,16 @@ def initialize(options={})
def run
if @options[:update] || @options[:clear]
write_crontab(updated_crontab)
elsif @options[:clear_all]
# Create a file if doesn't exist
system "crontab -l | sed 's/>/>>/' | crontab - "
# Remove crontab
system "crontab -r"
# Reinitialize
system "crontab -l | sed 's/>/>>/' | crontab - "

puts '[reset] Success to reboot crontab'
exit(0)
elsif @options[:write]
write_crontab(whenever_cron)
else
Expand Down