Class: Hotdog::Application
- Inherits:
-
Object
- Object
- Hotdog::Application
- Defined in:
- lib/hotdog/application.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #main(argv = []) ⇒ Object
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hotdog/application.rb', line 11 def initialize() @optparse = OptionParser.new @options = { api_key: ENV["DATADOG_API_KEY"], application_key: ENV["DATADOG_APPLICATION_KEY"], application: self, confdir: find_confdir(File.(".")), debug: false, expiry: 180, fixed_string: false, force: false, format: "plain", headers: false, listing: false, logger: Logger.new(STDERR).tap { |logger| logger.level = Logger::INFO }, max_time: 5, print0: false, print1: true, tags: [], verbose: false, } end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
36 37 38 |
# File 'lib/hotdog/application.rb', line 36 def @options end |
Instance Method Details
#main(argv = []) ⇒ Object
38 39 40 41 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 |
# File 'lib/hotdog/application.rb', line 38 def main(argv=[]) config = File.join([:confdir], "config.yml") if File.file?(config) loaded = YAML.load(File.read(config)) if Hash === loaded @options = @options.merge(Hash[loaded.map { |key, value| [Symbol === key ? key : key.to_s.to_sym, value] }]) end end args = @optparse.parse(argv) unless [:api_key] raise("DATADOG_API_KEY is not set") end unless [:application_key] raise("DATADOG_APPLICATION_KEY is not set") end [:formatter] = get_formatter([:format]).new if [:debug] or [:verbose] [:logger].level = Logger::DEBUG else [:logger].level = Logger::INFO end begin command = ( args.shift || "help" ) get_command(command).new(@options.dup).tap do |cmd| cmd.run(args) end rescue Errno::EPIPE # nop end end |