Module: Prompt::DSL

Included in:
Console::Builtins
Defined in:
lib/prompt/dsl.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/prompt/dsl.rb', line 7

def self.extended(base)
  name = if base.respond_to? :name
    base.name
  else
    "Commands"
  end
  Prompt.application.select_group(name)
end

Instance Method Details

#command(name, desc = nil, &block) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/prompt/dsl.rb', line 24

def command(name, desc = nil, &block)
  desc ||= @@last_desc
  @@last_desc = nil
  words = DSLHelper.words(name, @parameters || [])
  command = Command.new(words, desc, &block)
  Prompt.application.add_command(command)
end

#desc(text) ⇒ Object



16
17
18
# File 'lib/prompt/dsl.rb', line 16

def desc text
  @@last_desc = text
end

#group(desc) ⇒ Object



20
21
22
# File 'lib/prompt/dsl.rb', line 20

def group desc
  Prompt.application.select_group(desc)
end

#param(name, desc = nil, values = nil, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/prompt/dsl.rb', line 32

def param(name, desc = nil, values = nil, &block)
  desc ||= @@last_desc
  @@last_desc = nil
  @parameters = [] unless defined? @parameters
  raise "parameter :#{name} is already defined" if @parameters.find {|v| v.name == name}
  @parameters << if block
    Parameter.new(name, desc, &block)
  else
    Parameter.new(name, desc, values)
  end
end