Sha256: aa9198edc65eacd1a36d28f46b9d67ab93a83a54be3179316c368d7cef822eb3

Contents?: true

Size: 1.29 KB

Versions: 34

Compression:

Stored size: 1.29 KB

Contents

module TreasureData
module Command

  def apikey_show(op)
    if Config.apikey
      $stdout.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

    $stdout.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

    $stdout.puts "API key is set."
    $stdout.puts "Use '#{$prog} db:create <db_name>' to create a database."
  end

end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
td-0.17.1 lib/td/command/apikey.rb
td-0.17.0 lib/td/command/apikey.rb
td-0.16.10 lib/td/command/apikey.rb
td-0.16.9 lib/td/command/apikey.rb
td-0.16.8 lib/td/command/apikey.rb
td-0.16.7 lib/td/command/apikey.rb
td-0.16.6 lib/td/command/apikey.rb
td-0.16.5 lib/td/command/apikey.rb
td-0.16.4 lib/td/command/apikey.rb
td-0.16.3 lib/td/command/apikey.rb
td-0.16.1 lib/td/command/apikey.rb
td-0.16.0 lib/td/command/apikey.rb
td-0.15.9 lib/td/command/apikey.rb
td-0.15.8 lib/td/command/apikey.rb
td-0.15.7 lib/td/command/apikey.rb
td-0.15.6 lib/td/command/apikey.rb
td-0.15.5 lib/td/command/apikey.rb
td-0.15.4 lib/td/command/apikey.rb
td-0.15.3 lib/td/command/apikey.rb
td-0.15.2 lib/td/command/apikey.rb