Class: NeoBundle::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/neobundle/command_line.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV) ⇒ CommandLine

Returns a new instance of CommandLine.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/neobundle/command_line.rb', line 29

def initialize(args=ARGV)
  @arguments = {
    command: nil,
    config: {}
  }
  parser = self.option_parser
  parser.order!(args)
  command = args.shift.to_s.intern
  
  case command
  when :install, :clean, :list then
    @arguments[:command] = command
    parser.permute!(args)
  when :'', :help then
    parser.permute(['--help'])
  else
    raise NeoBundle::CommandLineError, 'Invalid command: %s' % command
  end
rescue OptionParser::ParseError => e
  raise NeoBundle::CommandLineError, e.message
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



6
7
8
# File 'lib/neobundle/command_line.rb', line 6

def arguments
  @arguments
end

Class Method Details

.runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/neobundle/command_line.rb', line 8

def self.run
  begin
    if block_given? then
      yield
    else
      self.new.execute
    end
  rescue NeoBundle::Error => e
    $stderr.puts e.message unless e.instance_of? NeoBundle::OperationAlreadyCompletedError
    exit e.status
  rescue SystemExit => e
    exit e.status
  rescue Exception => e
    $stderr.puts e.inspect
    $stderr.puts e.backtrace
    exit 1
  else
    exit 0
  end
end

Instance Method Details

#executeObject



51
52
53
54
# File 'lib/neobundle/command_line.rb', line 51

def execute
  runner = Runner.new(self.arguments[:config])
  runner.send(self.arguments[:command])
end