Class: NeoBundle::CommandLine
- Inherits:
-
Object
- Object
- NeoBundle::CommandLine
- Defined in:
- lib/neobundle/command_line.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(args = ARGV) ⇒ CommandLine
constructor
A new instance of CommandLine.
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/neobundle/command_line.rb', line 29 def initialize(args=ARGV) @arguments = { command: nil, config: {} } opt = OptionParser.new opt.version = NeoBundle::VERSION opt. = " Usage: neobundle [--help] [--version]\n [--vim=<path>] [--vimrc=<path>]\n <command>\n \n commands:\n install:\n $ neobundle install\n \n clean:\n $ neobundle clean\n \n list:\n $ neobundle list\n \n options:\n SH\n \n opt.on('--vim=<path>','Path to the vim command.'){|v| @arguments[:config][:vim] = v}\n opt.on('--vimrc=<path>','Path to the vimrc.'){|v| @arguments[:config][:vimrc] = v}\n opt.order!(args)\n \n command = args.shift.to_s.intern\n case command\n when :install, :clean, :list then\n @arguments[:command] = command\n opt.parse!(args)\n when :'', :help then\n opt.parse(['--help'])\n else\n raise NeoBundle::CommandLineError, 'Invalid command: %s' % command\n end\nrescue OptionParser::ParseError => e\n raise NeoBundle::CommandLineError, e.message\nend\n".gsub(/^( {2}){4}/,'') |
Instance Attribute Details
#arguments ⇒ Object (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
.run ⇒ Object
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. 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 255 else exit 0 end end |
Instance Method Details
#execute ⇒ Object
72 73 74 75 |
# File 'lib/neobundle/command_line.rb', line 72 def execute runner = Runner.new(self.arguments[:config]) runner.send(self.arguments[:command]) end |