lib/hygroscope/cli.rb in hygroscope-1.1.0 vs lib/hygroscope/cli.rb in hygroscope-1.1.1
- old
+ new
@@ -23,14 +23,10 @@
when /complete$/
set_color(status, :green)
end
end
- def word_wrap(string, length = 80, delim = $INPUT_RECORD_SEPARATOR)
- string.scan(/.{#{length}}|.+/).map(&:strip).join(delim)
- end
-
def countdown(text, time = 5)
print "#{text} "
time.downto(0) do |i|
$stdout.write("\b")
$stdout.write(i)
@@ -64,44 +60,47 @@
t = Hygroscope::Template.new(template_path)
# If the paramset exists load it, otherwise instantiate an empty one
p = Hygroscope::ParamSet.new(options[:paramset])
- # User provided a paramset, so load it and determine which parameters
- # are set and which need to be prompted.
if options[:paramset]
- pkeys = p.parameters.keys
- tkeys = t.parameters.keys
+ # User provided a paramset, so load it and determine which parameters
+ # are set and which need to be prompted.
+ paramset_keys = p.parameters.keys
+ template_keys = t.parameters.keys
- # Filter out any parameters that are not present in the template
- filtered = pkeys - tkeys
- pkeys = pkeys.select { |k, _v| tkeys.include?(k) }
- say_status('info', "Keys in paramset not requested by template: #{filtered.join(', ')}", :blue) unless filtered.empty?
+ # Reject any keys in paramset that are not requested by template
+ rejected_keys = paramset_keys - template_keys
+ say_status('info', "Keys in paramset not requested by template: #{rejected_keys.join(', ')}", :blue) unless rejected_keys.empty?
- # If ask option was passed, consider every parameter missing
- missing = options[:ask] ? tkeys : tkeys - pkeys
+ # Prompt for any key that is missing. If "ask" option was passed,
+ # prompt for every key.
+ missing = options[:ask] ? template_keys : template_keys - paramset_keys
else
# No paramset provided, so every parameter is missing!
missing = t.parameters.keys
end
- # If an existing stack was specified, load its outputs
if options[:existing]
+ # User specified an existing stack from which to pull outputs and
+ # translate into parameters. Load the existing stack.
e = Hygroscope::Stack.new(options[:existing])
say_status('info', "Populating parameters from #{options[:existing]} stack", :blue)
- # Fill any template paramater that matches an output of existing stack,
- # overriding parameters in the paramset. User can still change these if
- # they were missing from paramset or --ask option is passed.
+ # Fill any template parameter that matches an output from the existing
+ # stack, overwriting values from the paramset object. The user will
+ # be prompted to change these if they were not in the paramset or the
+ # --ask option was passed.
e.describe.outputs.each do |o|
p.set(o.output_key, o.output_value) if t.parameters.keys.include?(o.output_key)
end
end
- # Prompt for each missing param and save it to the paramset
+ # Prompt for each missing parameter and save it in the paramset object
missing.each do |key|
- # Do not prompt for keys prefixed with "Hygroscope"
+ # Do not prompt for keys prefixed with the "Hygroscope" reserved word.
+ # These parameters are populated internally without user input.
next if key =~ /^Hygroscope/
type = t.parameters[key]['Type']
default = p.get(key) ? p.get(key) : t.parameters[key]['Default'] || ''
description = t.parameters[key]['Description'] || false
@@ -130,11 +129,11 @@
end
# Offer to save paramset if it was modified
# Filter out keys beginning with "Hygroscope" since they are not visible
# to the user and may be modified on each invocation.
- unless missing.reject {|k| k =~ /^Hygroscope/}.empty?
+ unless missing.reject { |k| k =~ /^Hygroscope/ }.empty?
if yes?('Save changes to paramset?')
unless options[:paramset]
p.name = ask('Paramset name', :cyan, default: options[:name])
end
p.save!
@@ -144,18 +143,27 @@
# Upload payload
payload_path = File.join(Dir.pwd, 'payload')
if File.directory?(payload_path)
payload = Hygroscope::Payload.new(payload_path)
payload.prefix = options[:name]
- url = payload.upload!
- signed_url = payload.generate_url
- p.set('HygroscopePayload', url) if missing.include?('HygroscopePayload')
- p.set('HygroscopePayloadSignedUrl', signed_url) if missing.include?('HygroscopePayloadSignedUrl')
+ payload.upload!
+ p.set('HygroscopePayloadBucket', payload.bucket) if missing.include?('HygroscopePayloadBucket')
+ p.set('HygroscopePayloadKey', payload.key) if missing.include?('HygroscopePayloadKey')
+ p.set('HygroscopePayloadSignedUrl', payload.generate_url) if missing.include?('HygroscopePayloadSignedUrl')
say_status('ok', 'Payload uploaded to:', :green)
- say_status('', url)
+ say_status('', "s3://#{payload.bucket}/#{payload.key}")
end
+ # Set some additional parameters, if present
+ # HygroscopeAccountAzList
+ # HygroscopeAccountAzCount
+ #if missing.include?('HygroscopeAccountAzList') ||
+ # misisng.include?('HygroscopeAccountAzCount')
+ # p.set('HygroscopeAccountAzList', azlist) if missing.include?('HygroscopeAccountAzList')
+ # p.set('HygroscopeAccountAzCount', azlist) if missing.include?('HygroscopeAccountAzCount')
+ #end
+
[t, p]
end
desc 'create', "Create a new stack.\nUse the --name option to launch more than one stack from the same template.\nCommand prompts for parameters unless --paramset is specified.\nUse --existing to set parameters from an existing stack's outputs."
method_option :name,
@@ -219,9 +227,10 @@
s = Hygroscope::Stack.new(options[:name])
s.parameters = paramset.parameters
s.template = template.compress
s.capabilities = ['CAPABILITY_IAM']
+ s.timeout = 60
s.update!
status
end