Class: Classroom::Cli

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

Instance Method Summary collapse

Constructor Details

#initializeCli

Returns a new instance of Cli.



9
10
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
# File 'lib/classroom/cli.rb', line 9

def initialize
  require 'optparse'

  options = {}
  cli = OptionParser.new do |opts|
    opts.banner = "Usage: classroom [options]"

    opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
      options[:verbose] = v
    end
  end

  subcommands = { 
    'version' => Classroom::Commands::Version,
    'clone' => Classroom::Commands::Clone,
    'foo' => Classroom::Commands::Foo,
    'bar' => Classroom::Commands::Bar
  }

  cli.order!
  command = subcommands[ARGV.shift]
  if command
    command.optsparser.order! 
    command.new(options)
  else
    puts cli.help
  end
end