Class: RVC::CommandSlate
- Inherits:
-
Object
show all
- Includes:
- Util
- Defined in:
- lib/rvc/command_slate.rb
Overview
Execution environment for command definitions
Constant Summary
Constants included
from Util
Util::PROGRESS_BAR_LEFT, Util::PROGRESS_BAR_MIDDLE, Util::PROGRESS_BAR_RIGHT, Util::UserError
Instance Method Summary
collapse
Methods included from Util
#collect_children, #display_inventory, #err, #http_clone, #http_download, #http_upload, #interactive?, #menu, #metric, #one_progress, #progress, #retrieve_fields, #search_path, #single_connection, #status_color, #system_fg, #tasks, #tcsetpgrp, #terminal_columns
Constructor Details
Returns a new instance of CommandSlate.
31
32
33
|
# File 'lib/rvc/command_slate.rb', line 31
def initialize ns
@ns = ns
end
|
Instance Method Details
#lookup(path) ⇒ Object
95
96
97
|
# File 'lib/rvc/command_slate.rb', line 95
def lookup path
shell.fs.lookup path
end
|
#lookup!(path, types) ⇒ Object
103
104
105
|
# File 'lib/rvc/command_slate.rb', line 103
def lookup! path, types
shell.fs.lookup! path, types
end
|
#lookup_single(path) ⇒ Object
99
100
101
|
# File 'lib/rvc/command_slate.rb', line 99
def lookup_single path
shell.fs.lookup_single path
end
|
#lookup_single!(path, types) ⇒ Object
107
108
109
|
# File 'lib/rvc/command_slate.rb', line 107
def lookup_single! path, types
shell.fs.lookup_single! path, types
end
|
#opts(name, &b) ⇒ Object
Command definition functions
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/rvc/command_slate.rb', line 37
def opts name, &b
fail "command name must be a symbol" unless name.is_a? Symbol
if name.to_s =~ /[A-Z]/
fail "Camel-casing is not allowed (#{name})"
end
parser = OptionParser.new name.to_s, @ns.shell.fs, &b
summary = parser.summary?
parser.specs.each do |opt_name,spec|
if opt_name.to_s =~ /[A-Z]/
fail "Camel-casing is not allowed (#{name} option #{opt_name})"
end
end
@ns.commands[name] = Command.new @ns, name, summary, parser
end
|
#raw_opts(name, summary) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/rvc/command_slate.rb', line 56
def raw_opts name, summary
fail "command name must be a symbol" unless name.is_a? Symbol
if name.to_s =~ /[A-Z]/
fail "Camel-casing is not allowed (#{name})"
end
parser = RawOptionParser.new name.to_s
@ns.commands[name] = Command.new @ns, name, summary, parser
end
|
#rvc_alias(name, target = nil) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/rvc/command_slate.rb', line 74
def rvc_alias name, target=nil
fail "command name must be a symbol" unless name.is_a? Symbol
target ||= name
cmdpath = [name]
cur = @ns
while cur.parent
cmdpath << cur.name
cur = cur.parent
end
cmdpath.reverse!
shell.cmds.aliases[target] = cmdpath
end
|
#rvc_completor(name, &b) ⇒ Object
68
69
70
71
72
|
# File 'lib/rvc/command_slate.rb', line 68
def rvc_completor name, &b
fail "command name must be a symbol" unless name.is_a? Symbol
cmd = @ns.commands[name] or fail "command #{name} not defined"
cmd.completor = b
end
|
#shell ⇒ Object
91
92
93
|
# File 'lib/rvc/command_slate.rb', line 91
def shell
@ns.shell
end
|