Class: CLI

Inherits:
Object
  • Object
show all
Includes:
Mixlib::CLI
Defined in:
lib/madvertise/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for(cls, &block) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/madvertise/cli.rb', line 60

def self.for(cls, &block)
  cli = new
  cli.instance_eval(&block) if block_given?
  cli.parse_options

  $log.info("cli:initialize", cli.config)
  $conf.reload!

  # infer some variables
  opts = cli.config.merge({
    fqdn: Socket.gethostbyname(Socket.gethostname).first
  })

  # sneak in opts without subclassing
  cls.allocate.tap do |obj|
    obj.define_singleton_method(:opts) { opts }
    obj.send(:initialize)
  end
end

Instance Method Details

#option(name, args) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/madvertise/cli.rb', line 45

def option(name, args)
  args[:on] ||= :on
  args[:boolean] ||= false
  args[:required] ||= false
  args[:proc] ||= nil
  args[:show_options] ||= false
  args[:exit] ||= nil

  if args.has_key?(:default)
    config[name.to_sym] = args[:default]
  end

  options[name.to_sym] = args
end