Class: Jets::Commands::Configure
- Inherits:
-
Object
- Object
- Jets::Commands::Configure
- Extended by:
- Memoist
- Defined in:
- lib/jets/commands/configure.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Configure
constructor
A new instance of Configure.
- #load_yaml ⇒ Object
- #path ⇒ Object
- #pretty(path) ⇒ Object
- #prompt ⇒ Object
- #run ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(options) ⇒ Configure
Returns a new instance of Configure.
5 6 7 |
# File 'lib/jets/commands/configure.rb', line 5 def initialize() @options = end |
Instance Method Details
#load_yaml ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jets/commands/configure.rb', line 17 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.}".color(:yellow) {} end |
#path ⇒ Object
33 34 35 |
# File 'lib/jets/commands/configure.rb', line 33 def path "#{ENV['HOME']}/.jets/config.yml" end |
#pretty(path) ⇒ Object
29 30 31 |
# File 'lib/jets/commands/configure.rb', line 29 def pretty(path) path.sub(ENV['HOME'], '~') end |
#prompt ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/jets/commands/configure.rb', line 42 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 |
#run ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/jets/commands/configure.rb', line 9 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 |
#token ⇒ Object
37 38 39 |
# File 'lib/jets/commands/configure.rb', line 37 def token @options[:token] || prompt end |