Class: Linen::Plugin::SimpleCommand

Inherits:
Object
  • Object
show all
Includes:
CommandInfrastructure
Defined in:
lib/linen/simple_command.rb

Overview

A simple, single-phased command.

Authors

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

Instance Method Summary collapse

Methods included from CommandInfrastructure

#action, #can_inspect?, #execute, #help, #help_message, #initialize, #inspect, #require_confirmation, #requires_confirmation?

Instance Attribute Details

#nameObject (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