Class: Evoke::Task
- Inherits:
-
Object
- Object
- Evoke::Task
- Extended by:
- Comment, Parameters
- Defined in:
- lib/evoke/task.rb
Class Method Summary collapse
-
.desc(value) ⇒ String
A short, one line description of the task.
-
.print_syntax ⇒ Object
Prints the syntax usage for this task to the console.
-
.print_usage(name_col_size) ⇒ Object
Prints the name and description of this task to the console.
-
.syntax(value = nil) ⇒ String
Describes the syntax of the task.
-
.validate_arguments(arguments) ⇒ Object
Ensures that the task’s #invoke method has the same amount of arguments as the user supplied on the command-line.
Methods included from Comment
Methods included from Parameters
optional_parameters, parameter_names, parameter_size, required_parameters, select_parameters_by_type
Class Method Details
.desc(value) ⇒ String
All descriptions end with a period. One will be added if missing.
A short, one line description of the task.
This message will be printed to the console when evoke is called without any arguments.
36 37 38 39 |
# File 'lib/evoke/task.rb', line 36 def desc(value) value += '.' unless value.end_with?('.') @desc = value end |
.print_syntax ⇒ Object
Prints the syntax usage for this task to the console.
21 22 23 24 25 |
# File 'lib/evoke/task.rb', line 21 def print_syntax params = parameter_names(instance_method(:invoke)).join(' ') $stdout.puts "Usage: evoke #{name.underscore} #{params}" $stdout.puts "\n#{syntax}" end |
.print_usage(name_col_size) ⇒ Object
Prints the name and description of this task to the console.
11 12 13 14 15 16 17 |
# File 'lib/evoke/task.rb', line 11 def print_usage(name_col_size) description = "#{@desc || class_comment}".split("\n")[0] description ||= 'No description available.' $stdout.print name.underscore.ljust(name_col_size) $stdout.puts "# #{description}" end |
.syntax(value = nil) ⇒ String
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.
49 50 51 52 53 54 55 56 57 |
# 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) ⇒ Object
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.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# 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 |