Sha256: 8bb666532547aa1bac00142bead7926af44611da36152e349bae978c1d17bf33

Contents?: true

Size: 1.76 KB

Versions: 4

Compression:

Stored size: 1.76 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 parse_table_ident(table_ident)
    db_name, table_name = table_ident.split('.', 2)
    unless table_name
      $stderr.puts "Invalid table identifier '#{table_ident}'; expected 'DB.TABLE'"
      exit 1
    end
    return db_name, table_name
  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

4 entries across 4 versions & 1 rubygems

Version Path
td-0.9.3 lib/td/command/common.rb
td-0.9.2 lib/td/command/common.rb
td-0.9.1 lib/td/command/common.rb
td-0.9.0 lib/td/command/common.rb