Class: Houcho::CLI::Attribute

Inherits:
Thor
  • Object
show all
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



60
61
62
63
64
65
66
67
# File 'lib/houcho/cli/attribute.rb', line 60

def delete(attr_name = nil)
  options[: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



48
49
50
51
52
53
54
55
# File 'lib/houcho/cli/attribute.rb', line 48

def get(attr_name = nil)
  options[: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

#setObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/houcho/cli/attribute.rb', line 29

def set
  options[:target].each do |target_type, target_name|
    obj = Houcho::CLI::Attribute.target_type_obj(target_type)
    begin
      if options[:force]
        obj.set_attr!(target_name, options[:value])
      else
        obj.set_attr(target_name, options[:value])
      end
    rescue Houcho::AttributeExceptiotn=> e
      puts e.message
      exit!
    end
  end
end