Class: Shellissimo::DSL::CommandBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/shellissimo/dsl/command_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, param_builder_class = CommandParamBuilder) ⇒ CommandBuilder

Returns a new instance of CommandBuilder.



8
9
10
11
12
# File 'lib/shellissimo/dsl/command_builder.rb', line 8

def initialize(name, param_builder_class = CommandParamBuilder)
  @name = name
  @param_definitions = []
  @param_builder_class = param_builder_class
end

Instance Method Details

#description(desc) ⇒ Object



14
15
16
# File 'lib/shellissimo/dsl/command_builder.rb', line 14

def description(desc)
  @description = desc
end

#mandatory_param(name) ⇒ Object

Defines mandatory command param

See Also:



48
49
50
51
52
53
# File 'lib/shellissimo/dsl/command_builder.rb', line 48

def mandatory_param(name)
  build_param(name) do |p|
    p.mandatory!
    yield p if block_given?
  end
end

#param(name) {|| ... } ⇒ CommandParam

Defines a single command param (optional)

Parameters:

  • name (String)

    name for command param

Yield Parameters:

Returns:

See Also:



37
38
39
40
41
42
# File 'lib/shellissimo/dsl/command_builder.rb', line 37

def param(name)
  build_param(name) do |p|
    p.optional!
    yield p if block_given?
  end
end

#resultObject



55
56
57
# File 'lib/shellissimo/dsl/command_builder.rb', line 55

def result
  Command.new(String(@name), @description, @aliases, @param_definitions, &@block)
end

#run(&block) ⇒ Object

A block to run upon command execution



26
27
28
# File 'lib/shellissimo/dsl/command_builder.rb', line 26

def run(&block)
  @block = block
end

#shortcut(*aliases) ⇒ Object Also known as: shortcuts



18
19
20
# File 'lib/shellissimo/dsl/command_builder.rb', line 18

def shortcut(*aliases)
  @aliases = Array(aliases)
end