Class: Texico::CLI::Command::Config
- Defined in:
- lib/texico/cli/command/config.rb
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Base
inherited, #initialize, #load_config, match, priority, select
Constructor Details
This class inherits a constructor from Texico::CLI::Command::Base
Class Method Details
.match?(command) ⇒ Boolean
45 46 47 |
# File 'lib/texico/cli/command/config.rb', line 45 def match?(command) command == 'config' end |
Instance Method Details
#run ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/texico/cli/command/config.rb', line 7 def run config = if opts[:global] ConfigFile.global else load_config false end.to_hash did_change = false opts[:args].each do |key_value| key, value = key_value.split '=' key = key.to_sym did_change = did_change || config[key] != value config[key] = value end if did_change prompt.say "#{ICON} Writing new configuration\n", color: :bold else prompt.say "#{ICON} Current configuration\n", color: :bold end table = TTY::Table.new \ header: %w(Option Value).map { |v| prompt.decorate v, :bold }, rows: config.to_a prompt.say table.render(:basic) return unless did_change if opts[:global] ConfigFile.store(config, opts, ConfigFile::GLOBAL_CONFIG_PATH) else ConfigFile.store(config, opts) end end |