class Texico::CLI::Command::Config

Public Class Methods

match?(command) click to toggle source
# File lib/texico/cli/command/config.rb, line 45
def match?(command)
  command == 'config'
end

Public Instance Methods

run() click to toggle source
# 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