Class: Trooper::CLI

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/trooper/cli.rb', line 16

def initialize(argv)
  @argv = argv
  @options = { :environment => :production }

  @command = option_parser.parse!(@argv)[0]
  
  if @command 
    @command = @command.to_sym
  else
    raise CliArgumentError, "You didnt pass an action"
  end
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



13
14
15
# File 'lib/trooper/cli.rb', line 13

def argv
  @argv
end

#commandObject (readonly)

Returns the value of attribute command.



13
14
15
# File 'lib/trooper/cli.rb', line 13

def command
  @command
end

#configObject

Returns the value of attribute config.



14
15
16
# File 'lib/trooper/cli.rb', line 14

def config
  @config
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/trooper/cli.rb', line 13

def options
  @options
end

Class Method Details

.start(argv = ARGV) ⇒ Object



7
8
9
10
11
# File 'lib/trooper/cli.rb', line 7

def self.start(argv = ARGV)
  cli = self.new(argv)
  cli.execute
  cli
end

Instance Method Details

#executeObject



29
30
31
32
33
34
35
36
37
# File 'lib/trooper/cli.rb', line 29

def execute
  case command
  when :init
    Configuration.init
  else
    config = Configuration.new(options)
    config.runner(command).execute
  end
end