lib/command/info.rb in cpl-1.2.0 vs lib/command/info.rb in cpl-1.3.0
- old
+ new
@@ -30,33 +30,21 @@
def call
@missing_apps_workloads = {}
@missing_apps_starting_with = {}
- if config.app && !config.current[:match_if_app_name_starts_with]
+ if config.app && !config.should_app_start_with?(config.app)
single_app_info
else
multiple_apps_info
end
end
private
- def app_matches?(app, app_name, app_options)
- app == app_name.to_s || (app_options[:match_if_app_name_starts_with] && app.start_with?(app_name.to_s))
- end
-
- def find_app_options(app)
- @app_options ||= {}
- @app_options[app] ||= config.apps.find do |app_name, app_options|
- app_matches?(app, app_name, app_options)
- end&.last
- end
-
def find_workloads(app)
- app_options = find_app_options(app)
- return [] if app_options.nil?
+ app_options = config.find_app_config(app)
(app_options[:app_workloads] + app_options[:additional_workloads] + [app_options[:one_off_workload]]).uniq
end
def fetch_workloads(app)
@@ -73,25 +61,23 @@
result[app] ||= []
result[app].push(workload["name"])
end
if config.app
- result.select { |app, _| app_matches?(app, config.app, config.current) }
+ result.select { |app, _| config.app_matches?(app, config.app, config.current) }
else
- result.reject { |app, _| find_app_options(app).nil? }
+ result.reject { |app, _| config.find_app_config(app).nil? }
end
end
- def orgs # rubocop:disable Metrics/MethodLength
+ def orgs
result = []
if config.org
result.push(config.org)
else
- config.apps.each do |app_name, app_options|
- next if config.app && !app_matches?(config.app, app_name, app_options)
-
+ config.apps.each do |_, app_options|
org = app_options[:cpln_org]
result.push(org) if org && !result.include?(org)
end
end
@@ -100,22 +86,22 @@
def apps(org)
result = []
config.apps.each do |app_name, app_options|
- next if config.app && !app_matches?(config.app, app_name, app_options)
+ next if config.app && !config.app_matches?(config.app, app_name, app_options)
app_org = app_options[:cpln_org]
result.push(app_name.to_s) if app_org == org
end
result += @app_workloads.keys.map(&:to_s)
result.uniq.sort
end
def any_app_starts_with?(app)
- @app_workloads.keys.find { |app_name| app_matches?(app_name, app, config.apps[app.to_sym]) }
+ @app_workloads.keys.find { |app_name| config.app_matches?(app_name, app, config.apps[app.to_sym]) }
end
def check_any_app_starts_with(app)
if any_app_starts_with?(app)
false
@@ -182,12 +168,11 @@
puts "\nThere are no apps starting with some names. If you wish to create any, do so with " \
"(replace 'whatever' with whatever suffix you want):"
@missing_apps_starting_with.each do |app, _workloads|
- app_with_suffix = "#{app}#{app.end_with?('-') ? '' : '-'}whatever"
- puts " - `cpl setup-app -a #{app_with_suffix}`"
+ puts " - `cpl setup-app -a #{app}-whatever`"
end
end
def single_app_info
puts "#{Shell.color(config.org, :blue)}:"
@@ -195,11 +180,11 @@
print_app(config.app, config.org)
@defined_workloads = find_workloads(config.app)
@available_workloads = fetch_workloads(config.app)
- workloads = (@defined_workloads + @available_workloads).uniq.sort
+ workloads = (@defined_workloads + @available_workloads).uniq
workloads.each do |workload|
print_workload(config.app, workload)
end
print_missing_apps_workloads
@@ -215,10 +200,10 @@
next unless print_app(app, org)
@defined_workloads = find_workloads(app)
@available_workloads = @app_workloads[app] || []
- workloads = (@defined_workloads + @available_workloads).uniq.sort
+ workloads = (@defined_workloads + @available_workloads).uniq
workloads.each do |workload|
print_workload(app, workload)
end
end