Class: Prompt::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/prompt/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

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_groupsObject (readonly)

Returns the value of attribute command_groups.



9
10
11
# File 'lib/prompt/application.rb', line 9

def command_groups
  @command_groups
end

#promptObject

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

#commandsObject



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