Class: Assh::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/command.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Command

Returns a new instance of Command.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/command.rb', line 5

def initialize(argv)
  @args = argv
  parse_arguments!

  @configuration = Configuration.new

  @generator = Generator.new

  Provider.verbose! if @cmd_generate

  if @configuration.needs_generating? || @cmd_generate
    puts "Refreshing..."
    Provider.load_configuration!(@configuration, 'config.yml')
    @configuration.save_cache!
  else
    @configuration.load_cache!
  end

end

Instance Method Details

#execute!Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/command.rb', line 25

def execute!
  if @cmd_ls
    puts "Host List (cached at #{Time.at(@configuration.generated_at)})".green
    max_name = 0
    @configuration.groups.each do |name, hosts|
      hosts.each do |name, host|
        max_name = name.size if name.size > max_name
      end
    end
    @configuration.groups.each do |name, hosts|
      puts "  #{name.yellow}"
      hosts = Hash[hosts.sort]
      hosts.each do |name, host|
        padded_name = name + (" " * (max_name - name.size))
        puts "    #{padded_name.light_white} #{"-".green} #{host.address.cyan}"
      end
    end
  elsif @cmd_generate
    puts "Generating config in #{@generator.output_file}"
    generate!
    puts "Done"
  else
    generate!
    execute_default!
  end
end