Sha256: c02a940966d970e0ca19b7a7c9fc442768cdd276385d834fc6353dffe5f55987

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

require 'bone'

# TODO: finish this

class Bone::CLI < Drydock::Command
  
  def check!
    @token = @global.token || ENV['BONE_TOKEN']
    raise Bone::NoToken, @token unless Bone.token?(@token)
    Bone.token = @token
  end
  
  def get
    check!
    @argv.unshift @alias unless @alias == 'get'
    ## TODO: handle bone name=value
    ##if @alias.index('=') > 0
    ##  a = @alias.gsub(/\s+=\s+/, '=')
    ##  name, value = *( ? @argv.first.split('=') : @argv)
    ##end
    raise Bone::Problem, "No key specified" unless @argv.first
    ret = Bone.get(@argv.first)
    puts ret unless ret.nil? 
  end
  
  def set
    # TODO: use STDIN instead of @option.string
    check!
    name, value = *(@argv.size == 1 ? @argv.first.split('=') : @argv)
    raise Bone::Problem, "No key specified" unless name
    from_stdin = false
    if value.nil? && !stdin.tty? && !stdin.eof?
      from_stdin = true
      value = stdin.read
    end
    raise Bone::Problem, "Cannot set null value" unless value
    Bone[name] = value
    puts from_stdin ? '<STDIN>' : value
  end
  
  #def del
  #  check!
  #  raise Bone::Problem, "No key specified" unless @argv.first
  #  puts Bone.delete(@argv.first)
  #end
  
  def keys
    check!
    list = Bone.keys(@argv[0])
    if list.empty? 
      return if @global.quiet
      puts "No keys" 
      puts "Try: bone set keyname=keyvalue"
    else
      puts list
    end
  end
  
  def token
    check!
    puts Bone.token
  end

  def secret
    check!
    puts Bone.secret
  end
  
  def generate
    t, s = *Bone.generate
    unless t.nil?
      puts "# Your token for #{Bone.source}"
      puts "BONE_TOKEN=#{t}"
      puts "BONE_SECRET=#{s}"
    end
  #rescue Bone::NoToken => ex
  #  update_token_dialog
  #  exit 1
  end
  
  private 
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bone-0.3.1 lib/bone/cli.rb
bone-0.3.0 lib/bone/cli.rb