Class: Wavefront::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/wavefront/cli.rb

Direct Known Subclasses

Alerts, BatchWrite, Events, Ts, Write

Defined Under Namespace

Classes: Alerts, BatchWrite, Events, Ts, Write

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, arguments) ⇒ Cli



24
25
26
27
28
29
30
31
32
# File 'lib/wavefront/cli.rb', line 24

def initialize(options, arguments)
  @options   = options
  @arguments = arguments

  if options.include?(:help) && options[:help]
    puts options
    exit 0
  end
end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



22
23
24
# File 'lib/wavefront/cli.rb', line 22

def arguments
  @arguments
end

#optionsObject

Returns the value of attribute options.



22
23
24
# File 'lib/wavefront/cli.rb', line 22

def options
  @options
end

Instance Method Details

#load_profileObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/wavefront/cli.rb', line 34

def load_profile
  #
  # Load in configuration options from the (optionally) given
  # section of an ini-style configuration file. If the file's
  # not there, we don't consider that an error: it's not
  # entirely reasonable to demand the user has one. Options
  # passed on the command-line trump the same values in the
  # file.
  #
  return unless options[:config].is_a?(String)
  cf = Pathname.new(options[:config])
  return unless cf.exist?

  pf = options[:profile] || 'default'
  raw = IniFile.load(cf)
  profile = raw[pf]

  puts "using #{pf} profile from #{cf}" if options[:debug]

  profile.each_with_object({}) do |(k, v), memo|
    k = k.to_sym
    memo[k] = (options.include?(k) && options[k]) ? options[k] : v
  end
end