Class: Roast::Cogs::Cmd::Input

Inherits:
Roast::Cog::Input show all
Defined in:
lib/roast/cogs/cmd.rb

Overview

Input specification for the cmd cog

The cmd cog requires a command to execute, optionally with arguments. The command will be executed in the configured working directory.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInput

: () -> void



195
196
197
198
# File 'lib/roast/cogs/cmd.rb', line 195

def initialize
  super
  @args = []
end

Instance Attribute Details

#argsObject

Arguments to pass to the command

: Array



187
188
189
# File 'lib/roast/cogs/cmd.rb', line 187

def args
  @args
end

#commandObject

The command to execute

: String?



182
183
184
# File 'lib/roast/cogs/cmd.rb', line 182

def command
  @command
end

#stdinObject

Data to pass to command’s standard input

: String?



192
193
194
# File 'lib/roast/cogs/cmd.rb', line 192

def stdin
  @stdin
end

Instance Method Details

#coerce(input_return_value) ⇒ Object

Coerce the input from the return value of the input block

If the input block returns a String, it will be used as the command value. If the input block returns an Array, the first element will be used as the command and the remaining elements will be used as arguments.

#### See Also

  • ‘validate!`

: (String | Array) -> void



222
223
224
225
226
227
228
229
230
231
# File 'lib/roast/cogs/cmd.rb', line 222

def coerce(input_return_value)
  case input_return_value
  when String
    self.command = input_return_value
  when Array
    input_return_value.map!(&:to_s)
    self.command = input_return_value.shift
    self.args = input_return_value
  end
end

#validate!Object

Validate that the input has all required parameters

This method ensures that a command has been provided before the cmd cog executes.

#### See Also

  • ‘coerce`

: () -> void



208
209
210
# File 'lib/roast/cogs/cmd.rb', line 208

def validate!
  raise Cog::Input::InvalidInputError, "'command' is required" unless command.present?
end