Sha256: 3c9491c0770cce74b2270e41b5d2bb12c89c25fba631119664f1434c988ad829

Contents?: true

Size: 1.28 KB

Versions: 84

Compression:

Stored size: 1.28 KB

Contents

module TreasureData
module Command

  def apikey_show(op)
    if Config.apikey
      puts Config.apikey
      return
    end

    conf = nil
    begin
      conf = Config.read
    rescue ConfigError
    end

    if !conf || !conf['account.apikey']
      $stderr.puts "Account is not configured yet."
      $stderr.puts "Use '#{$prog} apikey:set' or '#{$prog} account' first."
      exit 1
    end

    puts conf['account.apikey']
  end

  def apikey_set(op)
    op.banner << "\noptions:\n"

    force = false
    op.on('-f', '--force', 'overwrite current account setting', TrueClass) {|b|
      force = true
    }

    apikey = op.cmd_parse

    conf = nil
    begin
      conf = Config.read
    rescue ConfigError
    end
    if conf && conf['account.apikey']
      unless force
        if conf['account.user']
          $stderr.puts "Account is already configured with '#{conf['account.user']}' account."
        else
          $stderr.puts "Account is already configured."
        end
        $stderr.puts "Add '-f' option to overwrite."
        exit 0
      end
    end

    conf ||= Config.new
    conf.delete("account.user")
    conf["account.apikey"] = apikey
    conf.save

    $stderr.puts "API key is set."

    $stderr.puts "Use '#{$prog} db:create <db_name>' to create a database."
  end

end
end

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
td-0.10.39 lib/td/command/apikey.rb
td-0.10.38 lib/td/command/apikey.rb
td-0.10.37 lib/td/command/apikey.rb
td-0.10.36 lib/td/command/apikey.rb
td-0.10.35 lib/td/command/apikey.rb
td-0.10.34 lib/td/command/apikey.rb
td-0.10.33 lib/td/command/apikey.rb
td-0.10.32 lib/td/command/apikey.rb
td-0.10.31 lib/td/command/apikey.rb
td-0.10.30 lib/td/command/apikey.rb
td-0.10.29 lib/td/command/apikey.rb
td-0.10.28 lib/td/command/apikey.rb
td-0.10.27 lib/td/command/apikey.rb
td-0.10.26 lib/td/command/apikey.rb
td-0.10.25 lib/td/command/apikey.rb
td-0.10.24 lib/td/command/apikey.rb
td-0.10.23 lib/td/command/apikey.rb
td-0.10.22 lib/td/command/apikey.rb
td-0.10.21 lib/td/command/apikey.rb
td-0.10.20 lib/td/command/apikey.rb