diff --git a/bin/whenever b/bin/whenever index 70a5bff6..bcb26433 100755 --- a/bin/whenever +++ b/bin/whenever @@ -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 diff --git a/lib/whenever/command_line.rb b/lib/whenever/command_line.rb index 46dd8a9f..70ecc468 100644 --- a/lib/whenever/command_line.rb +++ b/lib/whenever/command_line.rb @@ -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 @@ -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