Module: Roark::CLI

Defined in:
lib/roark/cli.rb,
lib/roark/cli/create.rb,
lib/roark/cli/shared.rb,
lib/roark/cli/destroy.rb

Defined Under Namespace

Modules: Shared Classes: Create, Destroy

Class Method Summary collapse

Class Method Details

.commandsObject



55
56
57
58
59
# File 'lib/roark/cli.rb', line 55

def self.commands
  return @commands if @commands
  klasses   = Roark::CLI.constants.reject {|c| [:Shared].include? c}
  @commands = klasses.map { |klass| Roark::CLI.const_get(klass).new }
end

.length_of_longest_commandObject



61
62
63
# File 'lib/roark/cli.rb', line 61

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

.startObject



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
# File 'lib/roark/cli.rb', line 11

def self.start
  cmd = ARGV.shift

  case cmd
  when 'create'
    begin
      CLI::Create.new.create
    rescue OptionParser::MissingArgument => e
      puts e.message
      exit 1
    end
  when 'destroy'
    begin
      CLI::Destroy.new.destroy
    rescue OptionParser::MissingArgument => e
      puts e.message
      exit 1
    end
  when '-h'
    usage
  when '-v'
    puts Roark::VERSION
  else
    puts "Unknown command: '#{cmd}'."
    puts ''
    usage
    exit 1
  end
end

.usageObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/roark/cli.rb', line 41

def self.usage
  puts 'Usage: roark command'
  puts ''
  puts 'Append -h for help on specific subcommand.'
  puts ''

  puts 'Commands:'
  commands.each do |cmd|
    $stdout.printf "    %-#{length_of_longest_command}s      %s\n",
                   cmd.command_name,
                   cmd.command_summary
  end
end