class Bookscan::CLI
Public Class Methods
new()
click to toggle source
# File lib/bookscan/cli.rb, line 8 def initialize @options = Hash.new @options[:debug] = false end
run(argv)
click to toggle source
# File lib/bookscan/cli.rb, line 44 def run(argv) self.new.execute(argv) end
Public Instance Methods
execute(argv)
click to toggle source
# 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)
click to toggle source
# File lib/bookscan/cli.rb, line 29 def usage(e=nil) puts @opt puts "\nCommands:\n" COMMANDS.each { |c| puts " " + c } end
version()
click to toggle source
# File lib/bookscan/cli.rb, line 37 def version File.open(File.dirname(__FILE__) + '/../../VERSION',"r") { |file| puts file.gets } end