Sha256: dc6b0e16a585d34b3758a78e3c89628f7af87d88b06e72194892b5d465d25e6a

Contents?: true

Size: 1.05 KB

Versions: 10

Compression:

Stored size: 1.05 KB

Contents

module Oci8Simple
  # == Description
  # A very thin wrapper around Oci8Simple::Client that handles ARGV / options and
  # formats the output in a manner suitable for printing on the console
  # == Usage
  #   cli = Oci8Simple::Cli.new
  #   cli.run "select id, name from foos" # "3, Bacon\n5, Cheese Puffs\n..."
  class Cli
    include Command
    
    attr_accessor :env, :client
    
    def initialize(env=nil)
      self.env = env
    end
    
    def run(sql, options={})
      format(client.run(sql, options), options)
    end
    
    def format(arr, options)
      if(options[:hash])
        arr.map{|row| row.map{|k,v| "#{k}: #{v}"}.join("\n")}.join("\n\n")
      else
        arr.map{|row| row.join(", ")}.join("\n")
      end
    end
    
    def client
      @client ||= Client.new(env)
    end
    
    def self.usage
      "Usage: #{$0} \"SQL\" [ENV]"
    end
    
    def self.run_from_argv
      o = parse_options(self.usage)
      if(ARGV[0].nil?)
        puts o
      else
        puts self.new(ARGV[1]).run(ARGV[0], @options)
      end
    end
    
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
oci8_simple-0.9.2 lib/oci8_simple/cli.rb
oci8_simple-0.9.1 lib/oci8_simple/cli.rb
oci8_simple-0.9.0 lib/oci8_simple/cli.rb
oci8_simple-0.8.5 lib/oci8_simple/cli.rb
oci8_simple-0.8.4 lib/oci8_simple/cli.rb
oci8_simple-0.8.3 lib/oci8_simple/cli.rb
oci8_simple-0.8.2 lib/oci8_simple/cli.rb
oci8_simple-0.8.1 lib/oci8_simple/cli.rb
oci8_simple-0.8.0 lib/oci8_simple/cli.rb
oci8_simple-0.7.0 lib/oci8_simple/cli.rb