Module: Philiprehberger::CliKit
- Defined in:
- lib/philiprehberger/cli_kit.rb,
lib/philiprehberger/cli_kit/menu.rb,
lib/philiprehberger/cli_kit/parser.rb,
lib/philiprehberger/cli_kit/prompt.rb,
lib/philiprehberger/cli_kit/spinner.rb,
lib/philiprehberger/cli_kit/version.rb
Defined Under Namespace
Modules: Menu, Prompt, Spinner Classes: Error, Parser
Constant Summary collapse
- VERSION =
'0.3.1'
Class Method Summary collapse
-
.ask(message, error: 'Invalid input, please try again.', input: $stdin, output: $stdout) {|answer| ... } ⇒ String
Display a prompt, re-asking until the answer satisfies the given block.
-
.confirm(message, input: $stdin, output: $stdout) ⇒ Boolean
Display a yes/no confirmation prompt.
-
.multi_select(message, choices, defaults: [], input: $stdin, output: $stdout) ⇒ Array<String>
Present a numbered menu allowing multiple selections and return the selected values.
-
.parse(args, output: $stdout) {|Parser| ... } ⇒ Parser
Parse command-line arguments using a DSL block.
-
.password(message, input: $stdin, output: $stdout) ⇒ String
Display a prompt and read input without echoing to the terminal.
-
.prompt(message, input: $stdin, output: $stdout) ⇒ String
Display a prompt and read user input.
-
.select(message, choices, default: nil, input: $stdin, output: $stdout) ⇒ String
Present a numbered menu and return the selected value.
-
.spinner(message, output: $stderr) { ... } ⇒ Object
Display a spinner while executing a block.
Class Method Details
.ask(message, error: 'Invalid input, please try again.', input: $stdin, output: $stdout) {|answer| ... } ⇒ String
Display a prompt, re-asking until the answer satisfies the given block.
71 72 73 |
# File 'lib/philiprehberger/cli_kit.rb', line 71 def self.ask(, error: 'Invalid input, please try again.', input: $stdin, output: $stdout, &block) Prompt.ask(, error: error, input: input, output: output, &block) end |
.confirm(message, input: $stdin, output: $stdout) ⇒ Boolean
Display a yes/no confirmation prompt.
48 49 50 |
# File 'lib/philiprehberger/cli_kit.rb', line 48 def self.confirm(, input: $stdin, output: $stdout) Prompt.confirm(, input: input, output: output) end |
.multi_select(message, choices, defaults: [], input: $stdin, output: $stdout) ⇒ Array<String>
Present a numbered menu allowing multiple selections and return the selected values.
105 106 107 |
# File 'lib/philiprehberger/cli_kit.rb', line 105 def self.multi_select(, choices, defaults: [], input: $stdin, output: $stdout) Menu.multi_select(, choices, defaults: defaults, input: input, output: output) end |
.parse(args, output: $stdout) {|Parser| ... } ⇒ Parser
Parse command-line arguments using a DSL block.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/philiprehberger/cli_kit.rb', line 19 def self.parse(args, output: $stdout, &) parser = Parser.new parser.instance_eval(&) parser.parse(args) if parser.help_requested? output.puts parser.help_text exit 0 unless output.is_a?(StringIO) end parser end |
.password(message, input: $stdin, output: $stdout) ⇒ String
Display a prompt and read input without echoing to the terminal.
58 59 60 |
# File 'lib/philiprehberger/cli_kit.rb', line 58 def self.password(, input: $stdin, output: $stdout) Prompt.password(, input: input, output: output) end |
.prompt(message, input: $stdin, output: $stdout) ⇒ String
Display a prompt and read user input.
38 39 40 |
# File 'lib/philiprehberger/cli_kit.rb', line 38 def self.prompt(, input: $stdin, output: $stdout) Prompt.prompt(, input: input, output: output) end |
.select(message, choices, default: nil, input: $stdin, output: $stdout) ⇒ String
Present a numbered menu and return the selected value.
93 94 95 |
# File 'lib/philiprehberger/cli_kit.rb', line 93 def self.select(, choices, default: nil, input: $stdin, output: $stdout) Menu.select(, choices, default: default, input: input, output: output) end |