Class: TempestTime::Commands::Config::Edit

Inherits:
TempestTime::Command show all
Defined in:
lib/tempest_time/commands/config/edit.rb

Instance Method Summary collapse

Methods inherited from TempestTime::Command

#command, #pastel, #prompt, #spinner, #table, #with_spinner, #with_success_fail_spinner

Constructor Details

#initialize(options) ⇒ Edit

Returns a new instance of Edit.



10
11
12
# File 'lib/tempest_time/commands/config/edit.rb', line 10

def initialize(options)
  @options = options
end

Instance Method Details

#execute(input: $stdin, output: $stdout) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tempest_time/commands/config/edit.rb', line 14

def execute(input: $stdin, output: $stdout)
  settings = TempestTime::Settings::Authorization
  setting = prompt.select(
    "Which #{pastel.green('setting')} would you like to edit?",
    settings.keys
  )

  new_value = prompt.ask(
    "Enter the #{pastel.green('new value')}.",
    default: settings.read(setting)
  )

  if new_value != settings.read(setting)
    settings.update(setting, new_value)
    prompt.say(pastel.green('Setting updated!'))
  else
    prompt.say('Nothing changed.')
  end

  execute if prompt.yes?('Keep editing?')
end