diff --git a/CHANGELOG.md b/CHANGELOG.md index d85a6161..bb679c70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ _Please add entries here for your pull requests that are not yet released._ - `build-image` command now accepts extra options and passes them to `docker build`. [PR 126](https://github.com/shakacode/heroku-to-control-plane/pull/126) by [Rafael Gomes](https://github.com/rafaelgomesxyz). - `CPLN_ORG_UPSTREAM` env var now takes precedence over config from `controlplane.yml` in `copy-image-from-upstream` command. [PR 137](https://github.com/shakacode/heroku-to-control-plane/pull/137) by [Rafael Gomes](https://github.com/rafaelgomesxyz). +- `info` command now works properly for apps with `match_if_app_name_starts_with` set to `true`.[PR 139](https://github.com/shakacode/heroku-to-control-plane/pull/139) by [Rafael Gomes](https://github.com/rafaelgomesxyz). +- `info` command now lists workloads in the same order as `controlplane.yml`. [PR 139](https://github.com/shakacode/heroku-to-control-plane/pull/139) by [Rafael Gomes](https://github.com/rafaelgomesxyz). ## [1.2.0] - 2024-01-03 diff --git a/lib/command/info.rb b/lib/command/info.rb index f2bf0d9b..1dbbdaf5 100644 --- a/lib/command/info.rb +++ b/lib/command/info.rb @@ -32,7 +32,7 @@ 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 @@ -41,20 +41,8 @@ def call 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 @@ -75,21 +63,19 @@ def fetch_app_workloads(org) # rubocop:disable Metrics/MethodLength 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 @@ -102,7 +88,7 @@ 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 @@ -113,7 +99,7 @@ def apps(org) 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) @@ -184,8 +170,7 @@ def print_missing_apps_starting_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 @@ -197,7 +182,7 @@ def single_app_info @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 @@ -217,7 +202,7 @@ def multiple_apps_info # rubocop:disable Metrics/MethodLength @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 diff --git a/lib/core/config.rb b/lib/core/config.rb index 7cde41fe..4c1f4936 100644 --- a/lib/core/config.rb +++ b/lib/core/config.rb @@ -102,6 +102,13 @@ def current end end + def app_matches?(app_name1, app_name2, app_options) + app_name1 && app_name2 && + (app_name1.to_s == app_name2.to_s || + (app_options[:match_if_app_name_starts_with] && app_name1.to_s.start_with?(app_name2.to_s)) + ) + end + def find_app_config(app_name1) @app_configs ||= {} @app_configs[app_name1] ||= apps.find do |app_name2, app_config| @@ -127,13 +134,6 @@ def ensure_config_app!(app_name, app_options) raise "Can't find config for app '#{app_name}' in 'controlplane.yml'." unless app_options end - def app_matches?(app_name1, app_name2, app_options) - app_name1 && app_name2 && - (app_name1.to_s == app_name2.to_s || - (app_options[:match_if_app_name_starts_with] && app_name1.to_s.start_with?(app_name2.to_s)) - ) - end - def ensure_app! return if app