class Evoke::Task

Public Class Methods

desc(value) click to toggle source

A short, one line description of the task.

This message will be printed to the console when evoke is called without any arguments.

@note All descriptions end with a period. One will be added if missing.

@param [String] value The description. Keep it short! @return [String] The supplied description.

# File lib/evoke/task.rb, line 36
def desc(value)
  value += '.' unless value.end_with?('.')
  @desc = value
end
print_syntax() click to toggle source

Prints the syntax usage for this task to the console. @private

print_usage(name_col_size) click to toggle source

Prints the name and description of this task to the console.

@param [Integer] name_col_size The size of the name column. @private

syntax(value=nil) click to toggle source

Describes the syntax of the task.

The syntax is displayed to the user when they call ‘evoke help` for this task. This can be a detailed, multi-line description of how to use the task. By default the comment before the task’s class will be used.

@param [String] value The details on how to use the task. @return [String] The syntax - this method is both a getter and setter.

# File lib/evoke/task.rb, line 49
def syntax(value=nil)
  if value.nil?
    @syntax ||= class_comment
  else
    @syntax = value unless value.nil?
  end

  @syntax
end
validate_arguments(arguments) click to toggle source

Ensures that the task’s invoke method has the same amount of arguments as the user supplied on the command-line. If not, an error message is printed to STDERR and Evoke is terminated with an exit-status of 1.

@param [Array] arguments The arguments to validate. @return nil if the validation passes. @private

# File lib/evoke/task.rb, line 66
def validate_arguments(arguments)
  invoke_method = instance_method(:invoke)
  min, max = parameter_size(invoke_method)

  size = Array(arguments).size
  return if size >= min && size <= max

  e_size = min == max ? min : "#{min}..#{max}"

  $stderr.print 'Wrong number of arguments. '
  $stderr.print "Received #{size} instead of #{e_size}.\n"

  exit(1)
end