From 3895bf59a60d9f43dd1292122f3402e35fc67498 Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: Fri, 17 Nov 2023 23:05:23 +0330 Subject: [PATCH] Move location assignment to config class --- lib/command/apply_template.rb | 2 +- lib/command/ps.rb | 2 +- lib/command/run.rb | 2 +- lib/command/run_detached.rb | 2 +- lib/core/config.rb | 4 +++- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/command/apply_template.rb b/lib/command/apply_template.rb index 0ca6bf28..20309fc2 100644 --- a/lib/command/apply_template.rb +++ b/lib/command/apply_template.rb @@ -127,7 +127,7 @@ def confirm_workload(template) def apply_template(filename) data = File.read(filename) .gsub("APP_GVC", config.app) - .gsub("APP_LOCATION", config.options[:location] || config[:default_location]) + .gsub("APP_LOCATION", config.location) .gsub("APP_ORG", config.org) .gsub("APP_IMAGE", latest_image) diff --git a/lib/command/ps.rb b/lib/command/ps.rb index 7445bb08..a7ea777a 100644 --- a/lib/command/ps.rb +++ b/lib/command/ps.rb @@ -26,7 +26,7 @@ class Ps < Base def call cp.fetch_gvc! - location = config.options["location"] || config[:default_location] + location = config.location workloads = [config.options[:workload]] if config.options[:workload] workloads ||= config[:app_workloads] + config[:additional_workloads] diff --git a/lib/command/run.rb b/lib/command/run.rb index 789e680f..b45d106e 100644 --- a/lib/command/run.rb +++ b/lib/command/run.rb @@ -57,7 +57,7 @@ class Run < Base attr_reader :location, :workload, :one_off, :container def call # rubocop:disable Metrics/MethodLength - @location = config.options["location"] || config[:default_location] + @location = config.location @workload = config.options["workload"] || config[:one_off_workload] @one_off = "#{workload}-run-#{rand(1000..9999)}" diff --git a/lib/command/run_detached.rb b/lib/command/run_detached.rb index c6b2e2e5..cec1629f 100644 --- a/lib/command/run_detached.rb +++ b/lib/command/run_detached.rb @@ -48,7 +48,7 @@ class RunDetached < Base # rubocop:disable Metrics/ClassLength attr_reader :location, :workload, :one_off, :container def call # rubocop:disable Metrics/MethodLength - @location = config.options["location"] || config[:default_location] + @location = config.location @workload = config.options["workload"] || config[:one_off_workload] @one_off = "#{workload}-runner-#{rand(1000..9999)}" diff --git a/lib/core/config.rb b/lib/core/config.rb index 7b47cce3..85c9e1c0 100644 --- a/lib/core/config.rb +++ b/lib/core/config.rb @@ -2,7 +2,7 @@ class Config # rubocop:disable Metrics/ClassLength attr_reader :config, :current, - :org, :org_comes_from_env, :app, :apps, :app_dir, + :org, :org_comes_from_env, :app, :apps, :app_dir, :location, # command line options :args, :options @@ -18,6 +18,8 @@ def initialize(args, options) load_app_config load_apps + @location = options[:location] || config.dig(:apps, app.to_sym, :default_location) + Shell.verbose_mode(options[:verbose]) end