Class: WIP::Runner::Command
- Inherits:
-
Object
- Object
- WIP::Runner::Command
show all
- Defined in:
- lib/wip/runner/command.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(ui) ⇒ Command
Returns a new instance of Command.
48
49
50
51
|
# File 'lib/wip/runner/command.rb', line 48
def initialize(ui)
@ui = ui
@parser = WIP::Runner::Parser.new(@ui, self.class)
end
|
Instance Attribute Details
#parser ⇒ Object
TODO(?)… :arguments, :options
46
47
48
|
# File 'lib/wip/runner/command.rb', line 46
def parser
@parser
end
|
Class Method Details
.argument(name, definition) ⇒ Object
26
27
28
|
# File 'lib/wip/runner/command.rb', line 26
def argument(name, definition)
arguments[name] = Options.new(definition)
end
|
.arguments(value = nil) ⇒ Object
30
31
32
|
# File 'lib/wip/runner/command.rb', line 30
def arguments(value = nil)
@arguments ||= {}
end
|
.commands ⇒ Object
22
23
24
|
# File 'lib/wip/runner/command.rb', line 22
def commands
@commands ||= Commands.within(self)
end
|
.options(&block) ⇒ Object
35
36
37
38
39
|
# File 'lib/wip/runner/command.rb', line 35
def options(&block)
@options ||= []
@options << block if block_given?
@options
end
|
.overview(value = nil) ⇒ Object
17
18
19
20
|
# File 'lib/wip/runner/command.rb', line 17
def overview(value = nil)
@overview = value unless value.nil?
@overview
end
|
.signature ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/wip/runner/command.rb', line 5
def signature
@signature ||= begin
ns = Commands.name
parts = self.name
.sub(/^.*(CLI|Commands)::/, '')
.split('::')
parts.map { |part| part.gsub(/([A-Z])/, "-\\1").sub(/^-/, '') }
.join(' ')
.downcase
end
end
|
.workflow(&block) ⇒ Object
41
42
43
|
# File 'lib/wip/runner/command.rb', line 41
def workflow(&block)
Workflow.define(&block)
end
|
Instance Method Details
#run(argv = []) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/wip/runner/command.rb', line 53
def run(argv = [])
begin
parser.run(argv) do |command, arguments, options|
if command.nil?
if options.help
parser.help
return
end
validate!(arguments)
execute(arguments, options)
else
command.match(/^-/) ? parser.help : delegate(command, argv)
end
end
rescue OptionParser::InvalidOption => e
raise InvalidOption, e.args.join(' ')
end
rescue InvalidArgument, InvalidArguments, InvalidCommand, InvalidOption, InvalidOptions => e
print_error(e)
end
|