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.
Instance Method Summary collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
49 |
# File 'lib/metanorma/cli/commands/config.rb', line 49 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
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/metanorma/cli/commands/config.rb', line 62 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.exist?(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
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/metanorma/cli/commands/config.rb', line 17 def get(name = nil) config, config_path = load_config([:global], create_default_config: false) if name.nil? && File.exist?(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
29 30 31 32 33 34 35 36 37 |
# File 'lib/metanorma/cli/commands/config.rb', line 29 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
40 41 42 43 44 45 46 47 |
# File 'lib/metanorma/cli/commands/config.rb', line 40 def unset(name) config, config_path = load_config([:global]) ypath = dig_path(name) deep_unset(config, *ypath) save_config(config, config_path) end |