Module: HammerCLI::Apipie::Options

Included in:
Command
Defined in:
lib/hammer_cli/apipie/options.rb

Instance Method Summary collapse

Instance Method Details

#get_option_value(opt_name) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/hammer_cli/apipie/options.rb', line 29

def get_option_value(opt_name)
  if respond_to?(HammerCLI.option_accessor_name(opt_name), true)
    send(HammerCLI.option_accessor_name(opt_name))
  else
    nil
  end
end

#method_options(options) ⇒ Object



5
6
7
# File 'lib/hammer_cli/apipie/options.rb', line 5

def method_options(options)
  method_options_for_params(resource.action(action).params, options)
end

#method_options_for_params(params, options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hammer_cli/apipie/options.rb', line 9

def method_options_for_params(params, options)
  opts = {}

  params.each do |p|
    if p.expected_type == :hash && !p.params.empty?
      opts[p.name] = method_options_for_params(p.params, options)
    else
      p_name = HammerCLI.option_accessor_name(p.name)
      if options.key?(p_name)
        opts[p.name] = options[p_name]
      elsif respond_to?(p_name, true)
        opt = send(p_name)
        opts[p.name] = opt unless opt.nil?
      end
    end
  end

  opts
end