Skip to content

Commit

Permalink
Follow the new config implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangarha committed Dec 18, 2023
1 parent 49811cf commit b024d77
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/core/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_relative "helpers"

class Config # rubocop:disable Metrics/ClassLength
attr_reader :org_comes_from_env, :app_comes_from_env, :location,
attr_reader :org_comes_from_env, :app_comes_from_env,
# command line options
:args, :options, :required_options

Expand All @@ -18,8 +18,6 @@ def initialize(args, options, required_options)

ensure_required_options!

@location = options[:location] || current&.dig(:default_location)

Shell.verbose_mode(options[:verbose])
end

Expand All @@ -31,6 +29,10 @@ def app
@app ||= load_app_from_options || load_app_from_env
end

def location
@location ||= load_location_from_options || load_location_from_env
end

def [](key)
ensure_current_config!

Expand Down Expand Up @@ -232,6 +234,20 @@ def load_org_from_file
strip_str_and_validate(current[:cpln_org])
end

def load_location_from_options
strip_str_and_validate(options[:location])
end

def load_location_from_env
strip_str_and_validate(ENV.fetch("CPLN_LOCATION", nil))
end

def load_location_from_file
return unless current&.key?(:default_location)

strip_str_and_validate(options[:default_location])
end

def warn_deprecated_options(app_options)
deprecated_option_keys = new_option_keys.select { |old_key| app_options.key?(old_key) }
return if deprecated_option_keys.empty?
Expand Down

0 comments on commit b024d77

Please sign in to comment.