Class: LilUtils::CLI::YesNo

Inherits:
OptionList show all
Defined in:
lib/lilutils/cli/cli.rb

Overview

A class that models the simple yes/no interaction with user on command line. Provides several ways to customize. @example: … Do you want to proceed [Y/n]? y (Enter) A simple Enter or ‘y’ returns the YES object. Pressing n returns NO object. Pressing anything else returns a value that depends on the mode which can be strict. If the mode is strict, it keeps on asking the user till s/he presses the correct key. If the mode is not strict, any invalid key (other than y, n, or enter) results in whatever the default option is. Note that the default option is shown as upper case key.

See Also:

  • CLI#YES
  • #NO

Constant Summary

Constants inherited from OptionList

OptionList::DEFAULT_PROMPT

Instance Method Summary collapse

Methods inherited from OptionList

#debug, #display_string, #show, #valid_response?

Constructor Details

#initialize(default_option = YES, prompt = DEFAULT_PROMPT, strict = true, istream = $stdin, ostream = $stdout) ⇒ YesNo

Creates a YesNo interaction.

Parameters:

  • default_option (Option) (defaults to: YES)

    the option that should be treated as default. Its default is #YES :-)

  • prompt (String) (defaults to: DEFAULT_PROMPT)

    prompt that should appear. Default is #DEFAULT_PROMPT

  • strict (Boolean) (defaults to: true)

    decides if the interaction should demand exact response and loop till user behaves

  • istream (IO) (defaults to: $stdin)

    input stream to read user response from

  • ostream (IO) (defaults to: $stdout)

    output stream to display output to



197
198
199
# File 'lib/lilutils/cli/cli.rb', line 197

def initialize(default_option=YES, prompt=DEFAULT_PROMPT, strict=true, istream=$stdin, ostream=$stdout)
  super(YN, YN.index(default_option), prompt, strict, istream, ostream)
end