Class: Bookscan::CLI
- Inherits:
-
Object
- Object
- Bookscan::CLI
- Defined in:
- lib/bookscan/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #execute(argv) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #usage(e = nil) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
8 9 10 11 |
# File 'lib/bookscan/cli.rb', line 8 def initialize @options = Hash.new @options[:debug] = false end |
Class Method Details
.run(argv) ⇒ Object
44 45 46 |
# File 'lib/bookscan/cli.rb', line 44 def run(argv) self.new.execute(argv) end |
Instance Method Details
#execute(argv) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bookscan/cli.rb', line 13 def execute(argv) begin @opt = OptionParser.new @opt.on('--version', 'show version') { version;exit } @opt.on('--help', 'show this message') { usage;exit } @opt.on('--debug', 'debug mode') { @options[:debug] = true } cmd_argv = @opt.order!(argv) cmd = cmd_argv.shift Commands.new(cmd_argv,@options).send(cmd) rescue =>e puts e usage raise e if @options[:debug] end end |
#usage(e = nil) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/bookscan/cli.rb', line 29 def usage(e=nil) puts @opt puts "\nCommands:\n" COMMANDS.each { |c| puts " " + c } end |
#version ⇒ Object
37 38 39 40 41 |
# File 'lib/bookscan/cli.rb', line 37 def version File.open(File.dirname(__FILE__) + '/../../VERSION',"r") { |file| puts file.gets } end |