diff --git a/lib/command/apply_template.rb b/lib/command/apply_template.rb index 591ddeae..b5d54856 100644 --- a/lib/command/apply_template.rb +++ b/lib/command/apply_template.rb @@ -43,7 +43,7 @@ class ApplyTemplate < Base # rubocop:disable Metrics/ClassLength VALIDATIONS = %w[config templates].freeze def call # rubocop:disable Metrics/MethodLength - @template_parser = TemplateParser.new(config) + @template_parser = TemplateParser.new(self) @names_to_filenames = config.args.to_h do |name| [name, @template_parser.template_filename(name)] end diff --git a/lib/command/doctor.rb b/lib/command/doctor.rb index 3f380caf..386b286b 100644 --- a/lib/command/doctor.rb +++ b/lib/command/doctor.rb @@ -29,7 +29,7 @@ def call validations = config.options[:validations].split(",") ensure_required_options!(validations) - doctor_service = DoctorService.new(config) + doctor_service = DoctorService.new(self) doctor_service.run_validations(validations) end diff --git a/lib/core/doctor_service.rb b/lib/core/doctor_service.rb index a528140f..2806b244 100644 --- a/lib/core/doctor_service.rb +++ b/lib/core/doctor_service.rb @@ -3,10 +3,12 @@ class ValidationError < StandardError; end class DoctorService - attr_reader :config + extend Forwardable - def initialize(config) - @config = config + def_delegators :@command, :config, :progress + + def initialize(command) + @command = command end def run_validations(validations, silent_if_passing: false) # rubocop:disable Metrics/MethodLength @@ -37,7 +39,7 @@ def validate_config end def validate_templates - @template_parser = TemplateParser.new(config) + @template_parser = TemplateParser.new(@command) filenames = Dir.glob("#{@template_parser.template_dir}/*.yml") templates = @template_parser.parse(filenames) @@ -97,8 +99,4 @@ def warn_deprecated_template_variables .join("\n") progress.puts("\n#{Shell.color("DEPRECATED: #{message}", :yellow)}\n#{list}\n\n") end - - def progress - $stderr - end end diff --git a/lib/core/maintenance_mode.rb b/lib/core/maintenance_mode.rb index 93051f2d..dfc476ac 100644 --- a/lib/core/maintenance_mode.rb +++ b/lib/core/maintenance_mode.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "forwardable" - class MaintenanceMode extend Forwardable diff --git a/lib/core/template_parser.rb b/lib/core/template_parser.rb index e8d520d2..ee7a6e9a 100644 --- a/lib/core/template_parser.rb +++ b/lib/core/template_parser.rb @@ -1,10 +1,14 @@ # frozen_string_literal: true class TemplateParser - attr_reader :config, :deprecated_variables + extend Forwardable - def initialize(config) - @config = config + def_delegators :@command, :config, :cp + + attr_reader :deprecated_variables + + def initialize(command) + @command = command end def template_dir @@ -69,8 +73,4 @@ def new_variables "APP_IMAGE" => "{{APP_IMAGE}}" } end - - def cp - @cp ||= Controlplane.new(config) - end end diff --git a/lib/cpflow.rb b/lib/cpflow.rb index 9701e37d..be0f94f4 100644 --- a/lib/cpflow.rb +++ b/lib/cpflow.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "date" +require "forwardable" require "dotenv/load" require "cgi" require "json" @@ -226,12 +227,14 @@ def self.process_option_params(params) Cpflow::Cli.show_info_header(config) if with_info_header + command = command_class.new(config) + if validations.any? && ENV.fetch("DISABLE_VALIDATIONS", nil) != "true" - doctor = DoctorService.new(config) + doctor = DoctorService.new(command) doctor.run_validations(validations, silent_if_passing: true) end - command_class.new(config).call + command.call rescue RuntimeError => e ::Shell.abort(e.message) end