Sha256: c78c979438d490a808f2489e845357abe6d83b9e3f4dfc9ca65ed23190f4b544

Contents?: true

Size: 1.02 KB

Versions: 34

Compression:

Stored size: 1.02 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)
        YAML.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

34 entries across 34 versions & 2 rubygems

Version Path
jets-3.2.2 lib/jets/commands/configure.rb
jets-3.2.1 lib/jets/commands/configure.rb
jets.benforeva-3.0.17.pre.mount.pre.fix lib/jets/commands/configure.rb
jets-3.2.0 lib/jets/commands/configure.rb
jets-3.1.5 lib/jets/commands/configure.rb
jets-3.1.4 lib/jets/commands/configure.rb
jets-3.1.3 lib/jets/commands/configure.rb
jets-3.1.2 lib/jets/commands/configure.rb
jets-3.1.1 lib/jets/commands/configure.rb
jets-3.1.0 lib/jets/commands/configure.rb
jets-3.0.23 lib/jets/commands/configure.rb
jets-3.0.22 lib/jets/commands/configure.rb
jets-3.0.21 lib/jets/commands/configure.rb
jets-3.0.20 lib/jets/commands/configure.rb
jets-3.0.19 lib/jets/commands/configure.rb
jets-3.0.18 lib/jets/commands/configure.rb
jets-3.0.17 lib/jets/commands/configure.rb
jets-3.0.16 lib/jets/commands/configure.rb
jets-3.0.15 lib/jets/commands/configure.rb
jets-3.0.14 lib/jets/commands/configure.rb