lib/openbd/openbd_cli.rb in openbd_api-0.3.0 vs lib/openbd/openbd_cli.rb in openbd_api-0.3.1
- old
+ new
@@ -1,29 +1,18 @@
class OpenbdCLI
def initialize(argv)
@argv = argv
+ parse_option
end
def call
- opts = Slop.parse do |o|
- o.banner = "Usage: openbd <method> [arguments] [options]"
- o.on '-v', '--version', 'print the version' do
- puts "openbd_api #{Openbd::VERSION}"
- exit
- end
- o.on '-h', '--help', 'print help' do
- puts o
- exit
- end
- end
-
if method_name.nil?
- puts opts
+ puts @opts
elsif params.empty?
- puts OpenBD.send(method_name)
+ puts OpenBD.send(method_name).to_json
else
- puts OpenBD.send(method_name, params)
+ puts OpenBD.send(method_name, params).to_json
end
end
private
@@ -31,7 +20,21 @@
@argv[0]
end
def params
@argv[1..-1]
+ end
+
+ def parse_option
+ @opts = Slop.parse do |o|
+ o.banner = "Usage: openbd <method> [arguments] [options]"
+ o.on '-v', '--version', 'print the version' do
+ puts "openbd_api #{Openbd::VERSION}"
+ exit
+ end
+ o.on '-h', '--help', 'print help' do
+ puts o
+ exit
+ end
+ end
end
end