class Commands::Command

Attributes

arg[RW]
commands[RW]
description[RW]
logger[RW]
name[RW]

Public Class Methods

new(name, description, arg, commands) click to toggle source
# File lib/commands.rb, line 101
def initialize(name, description, arg, commands)
  @name = name
  @description = description
  @arg = arg
  @commands = commands
  @logger = commands.logger
end

Public Instance Methods

enact(client) click to toggle source

action the command

# File lib/commands.rb, line 114
def enact(client)
end
get_field(field_symbol, default_value=nil) click to toggle source
# File lib/commands.rb, line 128
def get_field(field_symbol, default_value=nil)
  value = nil
  if respond_to?(field_symbol) then
    value = self.send(field_symbol)
  end
  if value == nil then
    value = @commands.global_options[field_symbol]
  end
  default_field_symbol = ("default_" + field_symbol.to_s).to_sym
  if value == nil && respond_to?(default_field_symbol) then
    value = self.send(default_field_symbol)
  end
  if value == nil then
    value = default_value
  end
  return value
end
has_value(obj, *args) click to toggle source
# File lib/commands.rb, line 159
def has_value(obj, *args)
  while obj != nil && args.size > 1 do
    obj = obj[args.shift]
  end
  return obj == args[0]
end
have(field_symbol) click to toggle source
# File lib/commands.rb, line 154
def have(field_symbol)
  value = get_field(field_symbol)
  return value != nil 
end
option(argument_name, argument_symbol, value) click to toggle source
# File lib/commands.rb, line 117
def option(argument_name, argument_symbol, value)
  var = self.send(argument_symbol)
  if var == nil then
    self.send((argument_symbol.to_s + "=").to_sym, value)
  elsif var.is_a?(Array) then
    var << value
  else
    raise RuntimeError, "Repeating #{argument_name} is not allowed, previous value was #{var.inspect}"
  end
end
require(field_symbol, error_msg) click to toggle source
# File lib/commands.rb, line 146
def require(field_symbol, error_msg)
  value = get_field(field_symbol)
  if value == nil then
    raise RuntimeError, error_msg
  end
  return value
end
require_single_jobflow() click to toggle source
# File lib/commands.rb, line 173
def require_single_jobflow
  jobflow_ids = get_field(:jobflow)
  if jobflow_ids.size == 0 then
    raise RuntimeError, "A jobflow is required to use option #{name}"
  elsif jobflow_ids.size > 1 then
    raise RuntimeError, "The option #{name} can only act on a single jobflow"
  end
  return jobflow_ids.first
end
resolve(obj, *args) click to toggle source
# File lib/commands.rb, line 166
def resolve(obj, *args)
  while obj != nil && args.size > 0 do
    obj = obj[args.shift]
  end
  return obj
end
validate() click to toggle source

test any constraints that the command has

# File lib/commands.rb, line 110
def validate
end