Module: Db::Clone::CmdPrompt

Included in:
Base
Defined in:
lib/db/clone/cmd_prompt.rb

Instance Method Summary collapse

Instance Method Details

#ask_yes_no(question, default_to_yes: true) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/db/clone/cmd_prompt.rb', line 14

def ask_yes_no question, default_to_yes: true
  if default_to_yes
    CLI::UI.confirm question
  else
    CLI::UI.ask(question, options: %w(no yes)) == 'yes'
  end
end

#fmt(text) ⇒ Object



35
36
37
# File 'lib/db/clone/cmd_prompt.rb', line 35

def fmt text
  CLI::UI.fmt text
end

#frame(title) ⇒ Object



8
9
10
11
12
# File 'lib/db/clone/cmd_prompt.rb', line 8

def frame(title)
  CLI::UI::Frame.open(title) do
    yield
  end
end

#prompt(question, default, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/db/clone/cmd_prompt.rb', line 22

def prompt question, default, options={}
  opts = options.reject { |key,| key == default }
  default_option = options[default]

  CLI::UI::Prompt.ask(question) do |handler|
    handler.option(default_option) { default }

    opts.each do |(value, text)|
      handler.option(text.to_s) { value }
    end
  end
end