Class: Basketcase::Command
- Inherits:
-
Object
- Object
- Basketcase::Command
- Extended by:
- Forwardable
- Includes:
- Utils
- Defined in:
- lib/basketcase/command.rb
Overview
Base ClearCase command
Direct Known Subclasses
AutoCommand, CheckinCommand, CheckoutCommand, DiffCommand, DirectoryModificationCommand, HelpCommand, LogCommand, LsCoCommand, LsCommand, UncheckoutCommand, UpdateCommand, VersionTreeCommand
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#listener ⇒ Object
writeonly
Sets the attribute listener.
-
#targets ⇒ Object
writeonly
Sets the attribute targets.
Instance Method Summary collapse
-
#accept_args(args) ⇒ Object
Handle command-line arguments: - For option arguments of the form “-X”, call the corresponding option_X() method.
- #effective_targets ⇒ Object
- #help ⇒ Object
-
#initialize(basketcase) ⇒ Command
constructor
A new instance of Command.
- #option_comment(comment) ⇒ Object (also: #option_m)
- #option_graphical ⇒ Object (also: #option_g)
- #option_recurse ⇒ Object (also: #option_r)
- #report(status, path, version = nil) ⇒ Object
- #specified_targets ⇒ Object
- #synopsis ⇒ Object
Methods included from Utils
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
#comment ⇒ Object
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
26 27 28 |
# File 'lib/basketcase/command.rb', line 26 def listener=(value) @listener = value end |
#targets=(value) ⇒ Object (writeonly)
Sets the attribute targets
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_targets ⇒ Object
73 74 75 |
# File 'lib/basketcase/command.rb', line 73 def effective_targets TargetList.new(@targets.empty? ? ['.'] : @targets) end |
#help ⇒ Object
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_graphical ⇒ Object Also known as: option_g
39 40 41 |
# File 'lib/basketcase/command.rb', line 39 def option_graphical @graphical = true end |
#option_recurse ⇒ Object 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_targets ⇒ Object
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 |
#synopsis ⇒ Object
11 12 13 |
# File 'lib/basketcase/command.rb', line 11 def synopsis "" end |