lib/command/apply_template.rb in cpl-1.1.2.rc.0 vs lib/command/apply_template.rb in cpl-1.1.2
- old
+ new
@@ -33,17 +33,16 @@
# Applies several templates (practically creating full app).
cpl apply-template gvc postgres redis rails -a $APP_NAME
```
EX
- def call # rubocop:disable Metrics/MethodLength
+ def call # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
ensure_templates!
- @app_status = :existing
- @created_workloads = []
- @failed_workloads = []
- @skipped_workloads = []
+ @created_items = []
+ @failed_templates = []
+ @skipped_templates = []
@asked_for_confirmation = false
pending_templates = templates.select do |template|
if template == "gvc"
@@ -55,25 +54,26 @@
progress.puts if @asked_for_confirmation
pending_templates.each do |template, filename|
step("Applying template '#{template}'", abort_on_error: false) do
- apply_template(filename)
- if $CHILD_STATUS.success?
- report_success(template)
+ items = apply_template(filename)
+ if items
+ items.each do |item|
+ report_success(item)
+ end
else
report_failure(template)
end
$CHILD_STATUS.success?
end
end
- print_app_status
- print_created_workloads
- print_failed_workloads
- print_skipped_workloads
+ print_created_items
+ print_failed_templates
+ print_skipped_templates
end
private
def templates
@@ -132,64 +132,39 @@
# Don't read in YAML.safe_load as that doesn't handle multiple documents
cp.apply_template(data)
end
- def report_success(template)
- if template == "gvc"
- @app_status = :success
- else
- @created_workloads.push(template)
- end
+ def report_success(item)
+ @created_items.push(item)
end
def report_failure(template)
- if template == "gvc"
- @app_status = :failure
- else
- @failed_workloads.push(template)
- end
+ @failed_templates.push(template)
end
def report_skipped(template)
- if template == "gvc"
- @app_status = :skipped
- else
- @skipped_workloads.push(template)
- end
+ @skipped_templates.push(template)
end
- def print_app_status
- return if @app_status == :existing
+ def print_created_items
+ return unless @created_items.any?
- case @app_status
- when :success
- progress.puts("\n#{Shell.color("Created app '#{config.app}'.", :green)}")
- when :failure
- progress.puts("\n#{Shell.color("Failed to create app '#{config.app}'.", :red)}")
- when :skipped
- progress.puts("\n#{Shell.color("Skipped app '#{config.app}' (already exists).", :blue)}")
- end
+ created = @created_items.map { |item| " - [#{item[:kind]}] #{item[:name]}" }.join("\n")
+ progress.puts("\n#{Shell.color('Created items:', :green)}\n#{created}")
end
- def print_created_workloads
- return unless @created_workloads.any?
+ def print_failed_templates
+ return unless @failed_templates.any?
- workloads = @created_workloads.map { |template| " - #{template}" }.join("\n")
- progress.puts("\n#{Shell.color('Created workloads:', :green)}\n#{workloads}")
+ failed = @failed_templates.map { |template| " - #{template}" }.join("\n")
+ progress.puts("\n#{Shell.color('Failed to apply templates:', :red)}\n#{failed}")
end
- def print_failed_workloads
- return unless @failed_workloads.any?
+ def print_skipped_templates
+ return unless @skipped_templates.any?
- workloads = @failed_workloads.map { |template| " - #{template}" }.join("\n")
- progress.puts("\n#{Shell.color('Failed to create workloads:', :red)}\n#{workloads}")
- end
-
- def print_skipped_workloads
- return unless @skipped_workloads.any?
-
- workloads = @skipped_workloads.map { |template| " - #{template}" }.join("\n")
- progress.puts("\n#{Shell.color('Skipped workloads (already exist):', :blue)}\n#{workloads}")
+ skipped = @skipped_templates.map { |template| " - #{template}" }.join("\n")
+ progress.puts("\n#{Shell.color('Skipped templates (already exist):', :blue)}\n#{skipped}")
end
end
end