Sha256: d839eae7142d1ae58b0bc20fe38f7a9cbd8adae8f11ae3e9476de29209fe5bb7

Contents?: true

Size: 1.03 KB

Versions: 13

Compression:

Stored size: 1.03 KB

Contents

module Jets::Commands
  class Configure
    extend Memoist

    def initialize(options)
      @options = options
    end

    def run
      data = load_yaml
      data['key'] = token
      FileUtils.mkdir_p(File.dirname(path))
      IO.write(path, YAML.dump(data))
      puts "Updated #{pretty(path)}"
    end

    def load_yaml
      if File.exist?(path)
        Jets::Util::Yamler.load_file(path)
      else
        {}
      end
    rescue Psych::SyntaxError => e
      puts "WARN: There was an error reading #{pretty(path)}".color(:yellow)
      puts "WARN: #{e.class} #{e.message}".color(:yellow)
      {}
    end

    def pretty(path)
      path.sub(ENV['HOME'], '~')
    end

    def path
      "#{ENV['HOME']}/.jets/config.yml"
    end

    def token
      @options[:token] || prompt
    end
    memoize :token

    def prompt
      puts <<~EOL
        You are about to configure your ~/.jets/config.yml
        You can get a token from serverlessgems.com
      EOL
      print "Please provide your token: "
      $stdin.gets.strip
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
jets-4.0.12 lib/jets/commands/configure.rb
jets-4.0.11 lib/jets/commands/configure.rb
jets-4.0.10 lib/jets/commands/configure.rb
jets-4.0.9 lib/jets/commands/configure.rb
jets-4.0.8 lib/jets/commands/configure.rb
jets-4.0.7 lib/jets/commands/configure.rb
jets-4.0.6 lib/jets/commands/configure.rb
jets-4.0.5 lib/jets/commands/configure.rb
jets-4.0.4 lib/jets/commands/configure.rb
jets-4.0.3 lib/jets/commands/configure.rb
jets-4.0.2 lib/jets/commands/configure.rb
jets-4.0.1 lib/jets/commands/configure.rb
jets-4.0.0 lib/jets/commands/configure.rb