Class: Metanorma::Cli::Commands::Config
- Inherits:
-
Thor
- Object
- Thor
- Metanorma::Cli::Commands::Config
- Defined in:
- lib/metanorma/cli/commands/config.rb
Class Method Summary collapse
- .exit_on_failure? ⇒ Boolean
-
.load_configs(options, configs = [Metanorma::Cli.global_config_path, Metanorma::Cli.local_config_path]) ⇒ Object
priority: IDEAL: thor defaults -> global conf -> local conf -> env vars -> passed arguments ACTUAL: all arguments -> global conf -> local conf - thor doesn't provide to differentiate default values against passed args - thor doesn't allow to get all args available for current command.
Instance Method Summary collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
43 |
# File 'lib/metanorma/cli/commands/config.rb', line 43 def self.exit_on_failure?() true end |
.load_configs(options, configs = [Metanorma::Cli.global_config_path, Metanorma::Cli.local_config_path]) ⇒ Object
priority: IDEAL: thor defaults -> global conf -> local conf -> env vars -> passed arguments ACTUAL: all arguments -> global conf -> local conf
-
thor doesn't provide to differentiate default values against passed args
-
thor doesn't allow to get all args available for current command
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/metanorma/cli/commands/config.rb', line 50 def self.load_configs(, configs = [Metanorma::Cli.global_config_path, Metanorma::Cli.local_config_path]) result = .dup configs.each do |config_path| next unless File.exists?(config_path) config_values = ::YAML::load_file(config_path).symbolize_all_keys[:cli] || {} result.merge!(config_values) end result end |
Instance Method Details
#get(name = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/metanorma/cli/commands/config.rb', line 12 def get(name = nil) config, config_path = load_config([:global], create_default_config: false) if name.nil? && File.exists?(config_path) UI.say File.read(config_path, encoding: "utf-8") else UI.say(config.dig(*dig_path(name)) || "nil") end end |
#set(name, value = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/metanorma/cli/commands/config.rb', line 23 def set(name, value = nil) config, config_path = load_config([:global]) value = try_convert_to_bool(value) ypath = dig_path(name) deep_set(config, value, *ypath) save_config(config, config_path) end |
#unset(name) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/metanorma/cli/commands/config.rb', line 34 def unset(name) config, config_path = load_config([:global]) ypath = dig_path(name) deep_unset(config, *ypath) save_config(config, config_path) end |