Module: ConfigmonkeyCli::Application::Dispatch

Included in:
ConfigmonkeyCli::Application
Defined in:
lib/configmonkey_cli/application/dispatch.rb

Instance Method Summary collapse

Instance Method Details

#dispatch(action = (@opts[:dispatch] || :help)) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/configmonkey_cli/application/dispatch.rb', line 4

def dispatch action = (@opts[:dispatch] || :help)
  if respond_to?("dispatch_#{action}")
    send("dispatch_#{action}")
  else
    abort("unknown action #{action}", 1)
  end
end

#dispatch_generate_manifestObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/configmonkey_cli/application/dispatch.rb', line 16

def dispatch_generate_manifest
  puts c("Not implemented", :red)
  # 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_helpObject



12
13
14
# File 'lib/configmonkey_cli/application/dispatch.rb', line 12

def dispatch_help
  puts @optparse.to_s
end

#dispatch_indexObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/configmonkey_cli/application/dispatch.rb', line 27

def dispatch_index
  Thread.abort_on_exception = true
  trap_signals

  @running = true
  load_and_execute_manifest
rescue Manifest::ExecutionError => ex
  error "\nTraceback (most recent call last):"
  ex.backtrace.reverse.each_with_index {|l, i| error "\t#{"#{ex.backtrace.length - i}:".rjust(4)} #{l}" }
  error "\n" << "[#{ex.class}] #{ex.message}".strip
ensure
  @running = false
  release_signals
end

#dispatch_infoObject



42
43
44
45
46
47
48
49
50
51
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
# File 'lib/configmonkey_cli/application/dispatch.rb', line 42

def dispatch_info
  your_version = Gem::Version.new(ConfigmonkeyCli::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(ConfigmonkeyCli::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 (#{$!.message})", :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 "  Configmonkey CLI is brought to you by #{c "bmonkeys.net", :green}"
  puts c "  Contribute @ #{c "github.com/2called-chaos/configmonkey_cli", :cyan}"
  puts c "  Eat bananas every day!"
  puts c ""
end