Class: Convoy::Setup::Dsl::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/convoy/setup/dsl/command.rb

Direct Known Subclasses

Global

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}, &block) ⇒ Command

Returns a new instance of Command.



5
6
7
8
9
10
11
12
13
# File 'lib/convoy/setup/dsl/command.rb', line 5

def initialize(name, options = {}, &block)
    reset(name)
    @description        = options[:description] || options[:desc] || ""
    @aliases            = [options[:aliases] || []].flatten
    @requires_arguments ||= options[:requires_arguments]
    block.call(self) if block_given?
rescue => e
    raise Convoy::ClientError.new("Problem with syntax of command '#{@name}' configuration", e)
end

Instance Method Details

#action(&block) ⇒ Object



19
20
21
# File 'lib/convoy/setup/dsl/command.rb', line 19

def action(&block)
    Action.action(@name, @action, &block)
end

#command(name, options = {}, &block) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/convoy/setup/dsl/command.rb', line 23

def command(name, options = {}, &block)
    options[:requires_arguments] = @requires_arguments
    command                      = Command.new(name.to_sym, options, &block)
    aliases                      = [options[:aliases] || []].flatten + [name]
    aliases.each do |name|
        @commands[name.to_sym] = command
    end
end

#description(description) ⇒ Object



44
45
46
# File 'lib/convoy/setup/dsl/command.rb', line 44

def description(description)
    @description = description
end

#options(&block) ⇒ Object



15
16
17
# File 'lib/convoy/setup/dsl/command.rb', line 15

def options(&block)
    Options.options(@name, @options, &block)
end

#requires_arguments(boolean = true) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/convoy/setup/dsl/command.rb', line 32

def requires_arguments(boolean = true)
    raise Convoy::ClientError.new("Parameter to 'requires_arguments' must be a boolean") unless [true, false].include?(boolean)
    @requires_arguments = boolean
    @commands.each do |command|
        command.requires_arguments(boolean)
    end
end

#summary(summary) ⇒ Object



40
41
42
# File 'lib/convoy/setup/dsl/command.rb', line 40

def summary(summary)
    @summary = summary
end