Sha256: 97498719f5f0e312f04b0df8ac8dde90ea0ca2c35d27787fbc5f601beea335a4

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

require 'colorize'

module Hackpad
  module Cli
    module Config
      module_function

      def load(options, input = STDIN, output = STDOUT)
        @input = input
        @output = output
        configdir = options[:configdir]
        configfile = File.join(configdir, "#{options[:workspace]}.yml")
        if !Dir.exist?(configdir) || !File.exist?(configfile)
          setup configfile, input, output
        end
        YAML.load_file configfile
      end

      def setup(configfile, input = STDIN, output = STDOUT)
        config = {}
        FileUtils.mkdir_p File.dirname(configfile)
        output.puts 'We need first to initialize your hackpad-cli configuration.'.blue
        output.puts 'Please gather your information from https://<subdomain>.hackpad.com/ep/account/settings/'.light_blue
        config['client_id'] = ask 'What is your Client ID?', input, output
        config['secret'] = ask 'What is your Secret Key?', input, output
        config['site'] = ask('What is the URI of your pad?', input, output).gsub(/\/$/, '')
        File.open(configfile, 'w') do |f|
          f.write YAML.dump(config)
        end
      end

      def ask(question, input, output)
        output.print "#{question} "
        back = input.gets.chomp
        output.flush
        back
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hackpad-cli-0.1.0 lib/hackpad/cli/config.rb