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,
lib/philiprehberger/cli_kit/colorize.rb
Defined Under Namespace
Modules: Colorize, Menu, Prompt, Spinner Classes: Error, Parser
Constant Summary collapse
- VERSION =
'0.5.0'
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.
- .bold(text) ⇒ String
-
.color(text, name) ⇒ String
Wraps text in ANSI color (auto-disabled when not a TTY or NO_COLOR is set).
-
.confirm(message, input: $stdin, output: $stdout) ⇒ Boolean
Display a yes/no confirmation prompt.
- .dim(text) ⇒ String
-
.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.
72 73 74 |
# File 'lib/philiprehberger/cli_kit.rb', line 72 def self.ask(, error: 'Invalid input, please try again.', input: $stdin, output: $stdout, &block) Prompt.ask(, error: error, input: input, output: output, &block) end |
.bold(text) ⇒ String
121 122 123 |
# File 'lib/philiprehberger/cli_kit.rb', line 121 def self.bold(text) Colorize.bold(text) end |
.color(text, name) ⇒ String
Wraps text in ANSI color (auto-disabled when not a TTY or NO_COLOR is set).
115 116 117 |
# File 'lib/philiprehberger/cli_kit.rb', line 115 def self.color(text, name) Colorize.color(text, name) end |
.confirm(message, input: $stdin, output: $stdout) ⇒ Boolean
Display a yes/no confirmation prompt.
49 50 51 |
# File 'lib/philiprehberger/cli_kit.rb', line 49 def self.confirm(, input: $stdin, output: $stdout) Prompt.confirm(, input: input, output: output) end |
.dim(text) ⇒ String
127 128 129 |
# File 'lib/philiprehberger/cli_kit.rb', line 127 def self.dim(text) Colorize.dim(text) end |
.multi_select(message, choices, defaults: [], input: $stdin, output: $stdout) ⇒ Array<String>
Present a numbered menu allowing multiple selections and return the selected values.
106 107 108 |
# File 'lib/philiprehberger/cli_kit.rb', line 106 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.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/philiprehberger/cli_kit.rb', line 20 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.
59 60 61 |
# File 'lib/philiprehberger/cli_kit.rb', line 59 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.
39 40 41 |
# File 'lib/philiprehberger/cli_kit.rb', line 39 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.
94 95 96 |
# File 'lib/philiprehberger/cli_kit.rb', line 94 def self.select(, choices, default: nil, input: $stdin, output: $stdout) Menu.select(, choices, default: default, input: input, output: output) end |