Sha256: a375e55470ff4790d5622b21c1481dc3ab2dfcd23cc4a0a6e18dbab1ef1fc817

Contents?: true

Size: 871 Bytes

Versions: 3

Compression:

Stored size: 871 Bytes

Contents

module OpenBD
  class OpenbdCLI
    def initialize(argv)
      @argv = argv
      parse_option
    end

    def call
      if method_name.nil?
        puts @opts
      elsif params.empty?
        client = ::OpenBD::Client.new
        puts client.send(method_name).body.to_json
      else
        client = ::OpenBD::Client.new
        puts client.send(method_name, params).body.to_json
      end
    end

    private

    def method_name
      @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
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
openbd_api-0.4.2 lib/openbd/openbd_cli.rb
openbd_api-0.4.1 lib/openbd/openbd_cli.rb
openbd_api-0.4.0 lib/openbd/openbd_cli.rb