Module: Heirloom::CLI

Defined in:
lib/heirloom/cli.rb,
lib/heirloom/cli/tag.rb,
lib/heirloom/cli/list.rb,
lib/heirloom/cli/show.rb,
lib/heirloom/cli/setup.rb,
lib/heirloom/cli/rotate.rb,
lib/heirloom/cli/shared.rb,
lib/heirloom/cli/upload.rb,
lib/heirloom/cli/catalog.rb,
lib/heirloom/cli/cleanup.rb,
lib/heirloom/cli/destroy.rb,
lib/heirloom/cli/download.rb,
lib/heirloom/cli/teardown.rb,
lib/heirloom/cli/authorize.rb,
lib/heirloom/cli/formatter/show.rb,
lib/heirloom/cli/formatter/catalog.rb

Defined Under Namespace

Modules: Formatter, Shared Classes: Authorize, Catalog, Cleanup, Destroy, Download, List, Rotate, Setup, Show, Tag, Teardown, Upload

Class Method Summary collapse

Class Method Details

.commandsObject



73
74
75
76
77
78
79
80
81
82
# File 'lib/heirloom/cli.rb', line 73

def self.commands
  return @commands if @commands
  klasses = Heirloom::CLI.constants.reject { |c| [:Shared, :Formatter].include?(c) }
  @commands = klasses.map do |klass|
    Hashie::Mash.new.tap do |h|
      h[:command_name]    = klass.downcase
      h[:command_summary] = Heirloom::CLI.const_get(klass).command_summary
    end
  end
end

.length_of_longest_commandObject



84
85
86
# File 'lib/heirloom/cli.rb', line 84

def self.length_of_longest_command
  @length ||= commands.map { |c| c.command_name.length }.max
end

.startObject



23
24
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
51
52
53
54
55
56
57
# File 'lib/heirloom/cli.rb', line 23

def self.start
  cmd = ARGV.shift

  case cmd
  when 'authorize'
    CLI::Authorize.new.authorize
  when 'catalog'
    CLI::Catalog.new.all
  when 'cleanup'
    CLI::Cleanup.new.cleanup
  when 'destroy', 'delete'
    CLI::Destroy.new.destroy
  when 'download'
    CLI::Download.new.download
  when 'list'
    CLI::List.new.list
  when 'rotate'
    CLI::Rotate.new.rotate
  when 'setup'
    CLI::Setup.new.setup
  when 'show'
    CLI::Show.new.show
  when 'tag', 'update'
    CLI::Tag.new.tag
  when 'teardown'
    CLI::Teardown.new.teardown
  when 'upload', 'build'
    CLI::Upload.new.upload
  when '-v'
    puts Heirloom::VERSION
  else
    puts "Unknown command: '#{cmd}'." unless cmd == '-h'
    usage
  end
end

.usageObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/heirloom/cli.rb', line 59

def self.usage
  puts ''
  puts 'Usage: heirloom command [options]'
  puts ''
  puts 'Append -h for help on specific command.'
  puts ''
  puts 'Commands:'
  commands.each do |cmd|
    $stdout.printf "    %-#{length_of_longest_command}s      %s\n",
                   cmd.command_name,
                   cmd.command_summary
  end
end