Class: Prompt::Application
- Inherits:
-
Object
- Object
- Prompt::Application
- Defined in:
- lib/prompt/application.rb
Instance Attribute Summary collapse
-
#command_groups ⇒ Object
readonly
Returns the value of attribute command_groups.
-
#prompt ⇒ Object
Returns the value of attribute prompt.
Instance Method Summary collapse
- #add_command(command) ⇒ Object
- #commands ⇒ Object
- #completions(line_starting_with, word_starting_with) ⇒ Object
- #exec(words) ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #select_group(desc) ⇒ Object
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
12 13 14 15 |
# File 'lib/prompt/application.rb', line 12 def initialize @command_groups = [] @prompt = "> " end |
Instance Attribute Details
#command_groups ⇒ Object (readonly)
Returns the value of attribute command_groups.
9 10 11 |
# File 'lib/prompt/application.rb', line 9 def command_groups @command_groups end |
#prompt ⇒ Object
Returns the value of attribute prompt.
10 11 12 |
# File 'lib/prompt/application.rb', line 10 def prompt @prompt end |
Instance Method Details
#add_command(command) ⇒ Object
21 22 23 |
# File 'lib/prompt/application.rb', line 21 def add_command command current_command_group.commands << command end |
#commands ⇒ Object
41 42 43 |
# File 'lib/prompt/application.rb', line 41 def commands @command_groups.map(&:commands).flatten(1) end |
#completions(line_starting_with, word_starting_with) ⇒ Object
35 36 37 38 39 |
# File 'lib/prompt/application.rb', line 35 def completions line_starting_with, word_starting_with args = Console.split(line_starting_with) last_idx = index_of_last_word(line_starting_with) all_completions(args[0,last_idx], word_starting_with) end |
#exec(words) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/prompt/application.rb', line 25 def exec words commands.each do |command| args = command.match(words) return command.run(args) if args end raise CommandNotFound.new ensure clear_cached_values end |
#select_group(desc) ⇒ Object
17 18 19 |
# File 'lib/prompt/application.rb', line 17 def select_group desc @current_command_group_name = desc end |