Sha256: 2bcc6c857e9e5403bb1430dd9bc1dfa0f96e298120af98a2065bbd16bd87c59c

Contents?: true

Size: 1.51 KB

Versions: 14

Compression:

Stored size: 1.51 KB

Contents

module TreasureData

autoload :API, 'td/client/api'
autoload :Client, 'td/client'
autoload :Database, 'td/client'
autoload :Table, 'td/client'
autoload :Schema, 'td/client'
autoload :Job, 'td/client'

module Command

  private
  def get_option(name)
    List.get_option(name)
  end

  def get_client
    apikey = Config.apikey
    unless apikey
      raise ConfigError, "Account is not configured."
    end
    Client.new(apikey)
  end

  def cmd_render_table(rows, *opts)
    require 'hirb'
    Hirb::Helpers::Table.render(rows, *opts)
  end

  def cmd_render_tree(nodes, *opts)
    require 'hirb'
    Hirb::Helpers::Tree.render(nodes, *opts)
  end

  def cmd_debug_error(ex)
    if $verbose
      $stderr.puts "error: #{$!.class}: #{$!.to_s}"
      $!.backtrace.each {|b|
        $stderr.puts "  #{b}"
      }
        $stderr.puts ""
    end
  end

  def get_database(client, db_name)
    begin
      return client.database(db_name)
    rescue
      cmd_debug_error $!
      $stderr.puts $!
      $stderr.puts "Use '#{$prog} database:list' to show the list of databases."
      exit 1
    end
    db
  end

  def get_table(client, db_name, table_name)
    db = get_database(client, db_name)
    begin
      table = db.table(table_name)
    rescue
      $stderr.puts $!
      $stderr.puts "Use '#{$prog} table:list #{db_name}' to show the list of tables."
      exit 1
    end
    #if type && table.type != type
    #  $stderr.puts "Table '#{db_name}.#{table_name} is not a #{type} table but a #{table.type} table"
    #end
    table
  end

end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
td-0.10.4 lib/td/command/common.rb
td-0.10.3 lib/td/command/common.rb
td-0.10.2 lib/td/command/common.rb
td-0.10.1 lib/td/command/common.rb
td-0.10.0 lib/td/command/common.rb
td-0.9.12 lib/td/command/common.rb
td-0.9.11 lib/td/command/common.rb
td-0.9.10 lib/td/command/common.rb
td-0.9.9 lib/td/command/common.rb
td-0.9.8 lib/td/command/common.rb
td-0.9.7 lib/td/command/common.rb
td-0.9.6 lib/td/command/common.rb
td-0.9.5 lib/td/command/common.rb
td-0.9.4 lib/td/command/common.rb