Class: Linecook::Command
- Inherits:
-
Object
show all
- Extended by:
- Lazydoc::Attributes
- Includes:
- Configurable
- Defined in:
- lib/linecook/command.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config = {}) ⇒ Command
Returns a new instance of Command.
46
47
48
|
# File 'lib/linecook/command.rb', line 46
def initialize(config={})
initialize_config(config)
end
|
Class Method Details
.help ⇒ Object
Returns a help string that formats the desc documentation.
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/linecook/command.rb', line 26
def help
lines = desc.kind_of?(Lazydoc::Comment) ? desc.wrap(78, 2, nil) : []
unless lines.empty?
line = '-' * 80
lines.unshift(line)
lines.push(line)
end
lines.join("\n")
end
|
.parse(argv = ARGV) {|parser| ... } ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/linecook/command.rb', line 6
def parse(argv=ARGV)
parser = configs.to_parser(:add_defaults => false)
yield(parser) if block_given?
parser.sort_opts!
parser.parse!(argv)
new(parser.config)
end
|
.signature ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/linecook/command.rb', line 15
def signature
arguments = args.arguments.collect do |arg|
arg = arg.upcase
arg[0] == ?* ? "[#{arg[1..-1]}]" : arg
end
arguments.pop if arguments.last.to_s[0] == ?&
"[options] #{arguments.join(' ')}"
end
|
Instance Method Details
#call(argv = []) ⇒ Object
50
51
52
|
# File 'lib/linecook/command.rb', line 50
def call(argv=[])
process(*argv)
end
|
#process(*args) ⇒ Object
54
55
56
|
# File 'lib/linecook/command.rb', line 54
def process(*args)
raise NotImplementedError
end
|