Class: Fontist::ConfigCLI

Inherits:
Thor
  • Object
show all
Includes:
Fontist::CLI::ClassOptions
Defined in:
lib/fontist/config_cli.rb

Instance Method Summary collapse

Methods included from Fontist::CLI::ClassOptions

#handle_class_options, included, #log_level

Instance Method Details

#delete(key) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/fontist/config_cli.rb', line 32

def delete(key)
  handle_class_options(options)
  Config.instance.delete(key)
  Fontist.ui.success(
    "'#{key}' reset to default ('#{Config.instance.default_value(key)}').",
  )
  CLI::STATUS_SUCCESS
end

#keysObject



42
43
44
45
46
47
48
49
# File 'lib/fontist/config_cli.rb', line 42

def keys
  handle_class_options(options)
  Fontist.ui.say("Available keys:")
  Config.instance.default_values.each do |key, value|
    Fontist.ui.say("#{key} (default: #{value})")
  end
  CLI::STATUS_SUCCESS
end

#set(key, value) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/fontist/config_cli.rb', line 21

def set(key, value)
  handle_class_options(options)
  Config.instance.set(key, value)
  Fontist.ui.success("'#{key}' set to '#{value}'.")
  CLI::STATUS_SUCCESS
rescue Errors::InvalidConfigAttributeError => e
  Fontist.ui.error(e.message)
  CLI::STATUS_INVALID_CONFIG_ATTRIBUTE
end

#showObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fontist/config_cli.rb', line 6

def show
  handle_class_options(options)
  values = Config.instance.custom_values

  if values.empty?
    Fontist.ui.success("Config is empty.")
  else
    Fontist.ui.success("Current config:")
    Fontist.ui.success(format_hash(values))
  end

  CLI::STATUS_SUCCESS
end