Class: Basketcase::Command

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Utils
Defined in:
lib/basketcase/command.rb

Overview

Base ClearCase command

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#mkpath

Constructor Details

#initialize(basketcase) ⇒ Command

Returns a new instance of Command.



19
20
21
22
23
24
# File 'lib/basketcase/command.rb', line 19

def initialize(basketcase)
  @basketcase = basketcase
  @listener = DefaultListener
  @recursive = false
  @graphical = false
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



51
52
53
# File 'lib/basketcase/command.rb', line 51

def comment
  @comment
end

#listener=(value) ⇒ Object (writeonly)

Sets the attribute listener

Parameters:

  • value

    the value to set the attribute listener to.



26
27
28
# File 'lib/basketcase/command.rb', line 26

def listener=(value)
  @listener = value
end

#targets=(value) ⇒ Object (writeonly)

Sets the attribute targets

Parameters:

  • value

    the value to set the attribute targets to.



27
28
29
# File 'lib/basketcase/command.rb', line 27

def targets=(value)
  @targets = value
end

Instance Method Details

#accept_args(args) ⇒ Object

Handle command-line arguments:

  • For option arguments of the form “-X”, call the corresponding option_X() method.

  • Remaining arguments are stored in @targets



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/basketcase/command.rb', line 57

def accept_args(args)
  while /^-+(.+)/ === args[0]
    option = args.shift
    option_method_name = "option_#{$1}"
    unless respond_to?(option_method_name)
      raise UsageException, "Unrecognised option: #{option}"
    end
    option_method = method(option_method_name)
    parameters = []
    option_method.arity.times { parameters << args.shift }
    option_method.call(*parameters)
  end
  @targets = args
  self
end

#effective_targetsObject



73
74
75
# File 'lib/basketcase/command.rb', line 73

def effective_targets
  TargetList.new(@targets.empty? ? ['.'] : @targets)
end

#helpObject



15
16
17
# File 'lib/basketcase/command.rb', line 15

def help
  "Sorry, no help provided ..."
end

#option_comment(comment) ⇒ Object Also known as: option_m



45
46
47
# File 'lib/basketcase/command.rb', line 45

def option_comment(comment)
  @comment = comment
end

#option_graphicalObject Also known as: option_g



39
40
41
# File 'lib/basketcase/command.rb', line 39

def option_graphical
  @graphical = true
end

#option_recurseObject Also known as: option_r



33
34
35
# File 'lib/basketcase/command.rb', line 33

def option_recurse
  @recursive = true
end

#report(status, path, version = nil) ⇒ Object



29
30
31
# File 'lib/basketcase/command.rb', line 29

def report(status, path, version = nil)
  @listener.call(ElementStatus.new(path, status, version))
end

#specified_targetsObject

Raises:



77
78
79
80
# File 'lib/basketcase/command.rb', line 77

def specified_targets
  raise UsageException, "No target specified" if @targets.empty?
  TargetList.new(@targets)
end

#synopsisObject



11
12
13
# File 'lib/basketcase/command.rb', line 11

def synopsis
  ""
end