Class: Alphonse::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/alphonse/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/alphonse/cli.rb', line 16

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

  @command = option_parser.parse!(@argv).delete_at(0)
  
  if @command
    @command = @command.to_sym
  else
    raise CliArgumentError, "An operation is required"
  end
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



7
8
9
# File 'lib/alphonse/cli.rb', line 7

def argv
  @argv
end

#commandObject (readonly)

Returns the value of attribute command.



7
8
9
# File 'lib/alphonse/cli.rb', line 7

def command
  @command
end

#configObject

Returns the value of attribute config.



8
9
10
# File 'lib/alphonse/cli.rb', line 8

def config
  @config
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/alphonse/cli.rb', line 7

def options
  @options
end

Class Method Details

.start(argv = ARGV) ⇒ Object



10
11
12
13
14
# File 'lib/alphonse/cli.rb', line 10

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/alphonse/cli.rb', line 29

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