Sha256: e538680324bef59adf9e15059ba38b8951a44d28a2023d989ccbf6b57c831095

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module Hackpad
  module Config
    extend self

    def load(dir = nil)
      if !Dir.exists?(conf_dir dir) || !File.exists?(conf_file)
        setup conf_dir dir
      end
      YAML::load_file conf_file
    end

  private

    def setup(dir)
      config = {}
      FileUtils.mkdir_p dir
      puts "We need first to initialize your hackpad-cli configuration.".colorize(:blue)
      puts "Please gather your information from https://<subdomain>.hackpad.com/ep/account/settings/"
      print "What is your Client ID?  "
      STDOUT.flush
      config['client_id'] = STDIN.gets.chomp
      print "What is your Secret Key? "
      STDOUT.flush
      config['secret'] = STDIN.gets.chomp
      print "What is the URI of your pad? "
      STDOUT.flush
      config['site'] = STDIN.gets.chomp
      File.open(conf_file, "w") do |f|
        f.write YAML::dump(config)
      end
    end

    def conf_file
      File.join(conf_dir, 'config.yml')
    end

    def conf_dir(dir = "#{ENV["HOME"]}/.hackpad-cli/")
      dir
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hackpad-cli-0.0.2 lib/hackpad/config.rb
hackpad-cli-0.0.1 lib/hackpad/config.rb