Class: Winever::CommandLine
- Inherits:
-
Object
- Object
- Winever::CommandLine
- Defined in:
- lib/winever/command_line.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#default_identifier ⇒ Object
protected.
-
#initialize(options = {}) ⇒ CommandLine
constructor
A new instance of CommandLine.
- #run ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ CommandLine
Returns a new instance of CommandLine.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/winever/command_line.rb', line 38 def initialize ={} @options = @options[:file] ||= 'config/schedule.rb' @options[:cut] ||= 0 @options[:identifier] ||= default_identifier unless File.exists?(@options[:file]) warn("[fail] Can't find file: #{@options[:file]}") exit(1) end if [@options[:update], @options[:clear]].compact.length > 1 warn("[fail] Can only update or clear. Choose one.") exit(1) end unless @options[:cut].to_s =~ /[0-9]*/ warn("[fail] Can't cut negative lines from the crontab #{[:cut]}") exit(1) end @options[:cut] = @options[:cut].to_i end |
Class Method Details
.execute(options = {}) ⇒ Object
34 35 36 |
# File 'lib/winever/command_line.rb', line 34 def self.execute ={} new().run end |
.run_from_command_line_options ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/winever/command_line.rb', line 4 def self. require 'optparse' = {} OptionParser.new do |opts| opts. = "Usage: whenever [options]" opts.on('-i', '--update [identifier]', 'Default: full path to schedule.rb file') do |identifier| [:update] = true [:identifier] = identifier if identifier end opts.on('-c', '--clear [identifier]') do |identifier| [:clear] = true [:identifier] = identifier if identifier end opts.on('-s', '--set [variables]', 'Example: --set \'environment=staging&path=/my/sweet/path\'') do |set| [:set] = set if set end opts.on('-f', '--load-file [schedule file]', 'Default: config/schedule.rb') do |file| [:file] = file if file end opts.on('-k', '--cut [lines]', 'Cut lines from the top of the cronfile') do |lines| [:cut] = lines.to_i if lines end opts.on('-v', '--version') { puts "Winever v#{Winever::VERSION}"; exit(0) } end.parse! self.execute() end |
Instance Method Details
#default_identifier ⇒ Object
protected
78 79 80 |
# File 'lib/winever/command_line.rb', line 78 def default_identifier File.(@options[:file]) end |
#run ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/winever/command_line.rb', line 63 def run if @options[:update] Winever::TaskManager.update_tasks(@options) elsif @options[:clear] Winever::TaskManager.clear_tasks(@options) else puts Winever::WheneverInterface.cron(@options) puts "## [message] Above is your schedule file converted to cron-winever syntax; your crontab file /scheduled tasks were not updated." puts "## [message] Run `winever --help' for more options." exit(0) end end |