Module: WatchmonkeyCli::Application::Dispatch
- Included in:
- WatchmonkeyCli::Application
- Defined in:
- lib/watchmonkey_cli/application/dispatch.rb
Instance Method Summary collapse
- #dispatch(action = (@opts[:dispatch] || :help)) ⇒ Object
- #dispatch_generate_config ⇒ Object
- #dispatch_help ⇒ Object
- #dispatch_index ⇒ Object
- #dispatch_info ⇒ Object
Instance Method Details
#dispatch(action = (@opts[:dispatch] || :help)) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/watchmonkey_cli/application/dispatch.rb', line 4 def dispatch action = (@opts[:dispatch] || :help) if respond_to?("dispatch_#{action}") fire(:dispatch_before, action) fire(:dispatch_around, action) do send("dispatch_#{action}") end fire(:dispatch_after, action) else abort("unknown action #{action}", 1) end end |
#dispatch_generate_config ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/watchmonkey_cli/application/dispatch.rb', line 20 def dispatch_generate_config cfg_name = @opts[:config_name] || "default" cfg_file = config_filename(cfg_name) puts c("Generating example config `#{cfg_name}'") if File.exist?(cfg_file) abort "Conflict, file already exists: #{cfg_file}", 1 else generate_config(cfg_name) puts c("Writing #{cfg_file}...", :green) end end |
#dispatch_help ⇒ Object
16 17 18 |
# File 'lib/watchmonkey_cli/application/dispatch.rb', line 16 def dispatch_help puts @optparse.to_s end |
#dispatch_index ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/watchmonkey_cli/application/dispatch.rb', line 32 def dispatch_index Thread.abort_on_exception = true trap_signals load_checkers! init_checkers! load_configs! dump_and_exit! if @opts[:dump] start_checkers! @running = true spawn_threads_and_run! @threads.each(&:join) # puts config_directory # puts config_files.inspect ensure @running = false stop_checkers! Timeout::timeout(@opts[:conclosewait]) { close_connections! } rescue false release_signals end |
#dispatch_info ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/watchmonkey_cli/application/dispatch.rb', line 52 def dispatch_info your_version = Gem::Version.new(WatchmonkeyCli::VERSION) puts c "" puts c(" Your version: ", :yellow) << c("#{your_version}", :magenta) print c(" Current version: ", :yellow) if @opts[:check_for_updates] require "net/http" print c("checking...", :blue) begin current_version = Gem::Version.new Net::HTTP.get_response(URI.parse(WatchmonkeyCli::UPDATE_URL)).body.strip if current_version > your_version status = c("#{current_version} (consider update)", :red) elsif current_version < your_version status = c("#{current_version} (ahead, beta)", :green) else status = c("#{current_version} (up2date)", :green) end rescue status = c("failed (#{$!.})", :red) end print "#{"\b" * 11}#{" " * 11}#{"\b" * 11}" # reset line puts status else puts c("check disabled", :red) end # more info puts c "" puts c " Watchmonkey CLI is brought to you by #{c "bmonkeys.net", :green}" puts c " Contribute @ #{c "github.com/2called-chaos/watchmonkey_cli", :cyan}" puts c " Eat bananas every day!" puts c "" end |