lib/command/base.rb in cpl-0.6.0 vs lib/command/base.rb in cpl-0.7.0
- old
+ new
@@ -151,10 +151,33 @@
required: required
}
}
end
+ def self.terminal_size_option(required: false)
+ {
+ name: :terminal_size,
+ params: {
+ banner: "ROWS,COLS",
+ desc: "Override remote terminal size (e.g. `--terminal-size 10,20`)",
+ type: :string,
+ required: required
+ }
+ }
+ end
+
+ def self.wait_option(title = "", required: false)
+ {
+ name: :wait,
+ params: {
+ desc: "Waits for #{title}",
+ type: :boolean,
+ required: required
+ }
+ }
+ end
+
def self.all_options
methods.grep(/_option$/).map { |method| send(method.to_s) }
end
def self.all_options_by_key_name
@@ -183,11 +206,11 @@
end
end
def ensure_workload_deleted(workload)
progress.puts "- Ensure workload is deleted"
- cp.workload_delete(workload)
+ cp.delete_workload(workload)
end
def latest_image_from(items, app_name: config.app, name_only: true)
matching_items = items.filter { |item| item["name"].start_with?("#{app_name}:") }
@@ -210,12 +233,13 @@
end
def latest_image_next(app = config.app, org = config.org)
@latest_image_next ||= {}
@latest_image_next[app] ||= begin
- image = latest_image(app, org).split(":").first
- image += ":#{extract_image_number(latest_image) + 1}"
+ latest_image_name = latest_image(app, org)
+ image = latest_image_name.split(":").first
+ image += ":#{extract_image_number(latest_image_name) + 1}"
image += "_#{config.options[:commit]}" if config.options[:commit]
image
end
end
@@ -227,32 +251,47 @@
def progress
$stderr
end
- def step(message, abort_on_error: true) # rubocop:disable Metrics/MethodLength
+ def step_error(error, abort_on_error: true)
+ message = error.message
+ if abort_on_error
+ progress.puts(" #{Shell.color('failed!', :red)}\n\n")
+ Shell.abort(message)
+ else
+ Shell.write_to_tmp_stderr(message)
+ end
+ end
+
+ def step_finish(success)
+ if success
+ progress.puts(" #{Shell.color('done!', :green)}")
+ else
+ progress.puts(" #{Shell.color('failed!', :red)}\n\n#{Shell.read_from_tmp_stderr}\n\n")
+ end
+ end
+
+ def step(message, abort_on_error: true, retry_on_failure: false) # rubocop:disable Metrics/MethodLength
progress.print("#{message}...")
Shell.use_tmp_stderr do
success = false
begin
- success = yield
- rescue RuntimeError => e
- message = e.message
- if abort_on_error
- progress.puts(" #{Shell.color('failed!', :red)}\n\n")
- Shell.abort(message)
+ if retry_on_failure
+ until (success = yield)
+ progress.print(".")
+ sleep 1
+ end
else
- Shell.write_to_tmp_stderr(message)
+ success = yield
end
+ rescue RuntimeError => e
+ step_error(e, abort_on_error: abort_on_error)
end
- if success
- progress.puts(" #{Shell.color('done!', :green)}")
- else
- progress.puts(" #{Shell.color('failed!', :red)}\n\n#{Shell.read_from_tmp_stderr}\n\n")
- end
+ step_finish(success)
end
end
def cp
@cp ||= Controlplane.new(config)