Class: Houcho::CLI::Attribute
- Inherits:
-
Thor
- Object
- Thor
- Houcho::CLI::Attribute
- Defined in:
- lib/houcho/cli/attribute.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.target_type_obj(target_type) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/houcho/cli/attribute.rb', line 10 def self.target_type_obj(target_type) case target_type when "role" Houcho::Role.new when "outerrole" Houcho::OuterRole.new when "host" Houcho::Host.new else Houcho::CLI::Main.empty_args(self, shell, __method__) # puts helps and exit(1) end end |
Instance Method Details
#delete(attr_name = nil) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/houcho/cli/attribute.rb', line 66 def delete(attr_name = nil) [:target].each do |target_type, target_name| obj = Houcho::CLI::Attribute.target_type_obj(target_type) obj.del_attr(target_name, attr_name).each do |k,v| print "#{k}:#{v} " end end end |
#get(attr_name = nil) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/houcho/cli/attribute.rb', line 54 def get(attr_name = nil) [:target].each do |target_type, target_name| obj = Houcho::CLI::Attribute.target_type_obj(target_type) obj.get_attr(target_name, attr_name).each do |k,v| puts "#{k.to_s.color(:red)}:#{v}" end end end |
#set(*args) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/houcho/cli/attribute.rb', line 28 def set(*args) Houcho::CLI::Main.empty_args(self, shell, __method__) if args.empty? value = {} args.each do |v| value = value.merge(Hash[*v.split(":")]) end [:target].each do |target_type, target_name| obj = Houcho::CLI::Attribute.target_type_obj(target_type) begin if [:force] obj.set_attr!(target_name, value) else obj.set_attr(target_name, value) end rescue Houcho::AttributeExceptiotn => e puts e. exit! end end end |