3
4
5
6
7
8
9
10
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
36
37
38
39
40
41
|
# File 'lib/knife-attribute/get.rb', line 3
def self.included(base)
base.class_eval do
include KnifeAttribute::CommonOptions
def run
check_arguments
if config[:attribute_type]
get_attribute(entity.send(attribute_type_map[config[:attribute_type].to_sym]))
elsif entity.respond_to?(:construct_attributes)
get_attribute(entity.construct_attributes)
else
get_attribute(entity.send(attribute_type_map[default_attribute_type]))
end
end
private
def check_arguments
if entity_name.nil?
show_usage
ui.fatal("You must specify a #{entity_type.to_s} name")
exit 1
end
if attribute.nil?
show_usage
ui.fatal('You must specify an attribute')
exit 1
end
check_type
end
def get_attribute(target)
result = ui.presenter.(target, attribute)
output(format_for_display(result))
end
end
end
|