Class: Linen::Plugin::SimpleCommand
- Inherits:
-
Object
- Object
- Linen::Plugin::SimpleCommand
- Includes:
- CommandInfrastructure
- Defined in:
- lib/linen/simple_command.rb
Overview
A simple, single-phased command.
Authors
-
Ben Bleything <[email protected]>
Copyright
Copyright © 2007 Laika, Inc.
This code released under the terms of the BSD license.
Version
$Id: simple_command.rb 407 2007-12-14 17:13:55Z bbleything $
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#one_of(*args) ⇒ Object
PLUGIN DEFINITION METHODS #.
- #required_arguments(*args) ⇒ Object (also: #required_argument)
-
#validate_arguments(args) ⇒ Object
HELPER METHODS #.
Methods included from CommandInfrastructure
#action, #can_inspect?, #execute, #help, #help_message, #initialize, #inspect, #require_confirmation, #requires_confirmation?
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/linen/simple_command.rb', line 23 def name @name end |
Instance Method Details
#one_of(*args) ⇒ Object
PLUGIN DEFINITION METHODS #
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/linen/simple_command.rb', line 29 def one_of( *args ) raise Linen::Plugin::ArgumentError, "You may not specify both required and one_of arguments" if @argument_type == :required @argument_type = :one_of args.each do |arg| raise Linen::Plugin::ArgumentError, "Argument '#{arg}' has not been defined" unless @plugin.arguments.include? arg @arguments << arg end end |
#required_arguments(*args) ⇒ Object Also known as: required_argument
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/linen/simple_command.rb', line 44 def required_arguments( *args ) raise Linen::Plugin::ArgumentError, "You may not specify both required and one_of arguments" if @argument_type == :one_of @argument_type = :required args.each do |arg| raise Linen::Plugin::ArgumentError, "Argument '#{arg}' has not been defined" unless @plugin.arguments.include? arg @arguments << arg end end |
#validate_arguments(args) ⇒ Object
HELPER METHODS #
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/linen/simple_command.rb', line 64 def validate_arguments( args ) if @argument_type == :one_of return validate_one_of_arguments( args.first ) else # @argument_type == :required return validate_required_arguments( args ) end # this is a Can't Happen(tm) so I'm comfortable with the crappy # exception string. :P raise "Something has happened!" end |