Class: Zillabyte::Command::Base
- Inherits:
-
Object
- Object
- Zillabyte::Command::Base
show all
- Includes:
- ActionView::Helpers::DateHelper, Helpers
- Defined in:
- lib/zillabyte/cli/base.rb
Direct Known Subclasses
Auth, Data, Flows, Git, Help, Keys, Nuke, Query, Repl, Version, Runner::AppRunner, Runner::ComponentRunner
Constant Summary
collapse
- META_COLUMNS =
["since", "confidence", "source"]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helpers
#add_git_remote, #app, #ask, #create_git_remote, #display, #error, #extract_app_from_git_config, #extract_app_in_dir, #format_with_bang, #get_flow_name, #git, #handle_downloading_manifest, #has_git?, #longest, #read_multiline, #with_tty
Constructor Details
#initialize(args = [], options = {}) ⇒ Base
Returns a new instance of Base.
19
20
21
22
|
# File 'lib/zillabyte/cli/base.rb', line 19
def initialize(args=[], options={})
@args = args
@options = options
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
16
17
18
|
# File 'lib/zillabyte/cli/base.rb', line 16
def args
@args
end
|
#options ⇒ Object
Returns the value of attribute options.
17
18
19
|
# File 'lib/zillabyte/cli/base.rb', line 17
def options
@options
end
|
Class Method Details
.alias_command(new, old) ⇒ Object
109
110
111
|
# File 'lib/zillabyte/cli/base.rb', line 109
def self.(help)
help.first
end
|
117
118
119
120
121
|
# File 'lib/zillabyte/cli/base.rb', line 117
def self.(help)
help.reject do |line|
line =~ /^\s+-(.+)#(.+)/
end.join("\n")
end
|
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/zillabyte/cli/base.rb', line 90
def self.(file, line_number)
buffer = []
lines = Zillabyte::Command.files[file]
(line_number.to_i-2).downto(0) do |i|
line = lines[i]
case line[0..0]
when ""
when "#"
buffer.unshift(line[1..-1])
else
break
end
end
buffer
end
|
Parse the caller format and identify the file and line number as identified
in : http://www.ruby-doc.org/core/classes/Kernel.html#M001397. This will
look for a colon followed by a digit as the delimiter. The biggest
complication is windows paths, which have a colon after the drive letter.
This regex will match paths as anything from the beginning to a colon
directly followed by a number (the line number).
Examples of the caller format :
- c:/Ruby192/lib/.../lib/zillabyte/cli/addons.rb:8:in `module:Command'
- c:/Ruby192/lib/.../zillabyte-2.0.1/lib/zillabyte/cli/pg.rb:96:in `class:Pg'
- /Users/ph7/...../xray-1.1/lib/xray/thread_dump_signal_handler.rb:9
81
82
83
84
85
86
87
88
|
# File 'lib/zillabyte/cli/base.rb', line 81
def self.(line)
if line =~ /^(.+?):(\d+)/
($1, $2)
else
raise("unable to extract help from caller: #{line}")
end
end
|
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/zillabyte/cli/base.rb', line 123
def self.(help)
r = help.select do |line|
line =~ /^\s+-(.+)#(.+)/
end.inject([]) do |options, line|
args = line.split('#', 2).first
args = args.split(/,\s*/).map {|arg| arg.strip}.sort.reverse
name = args.last.split(' ', 2).first[2..-1]
options << { :name => name, :args => args }
end
end
|
113
114
115
|
# File 'lib/zillabyte/cli/base.rb', line 113
def self.(help)
(help).split("\n")[2].to_s.split("\n").first
end
|
.inherited(klass) ⇒ Object
.method_added(method) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/zillabyte/cli/base.rb', line 42
def self.method_added(method)
return if self == Zillabyte::Command::Base
return if private_method_defined?(method)
return if protected_method_defined?(method)
help = (caller.first)
resolved_method = (method.to_s == "index") ? nil : method.to_s
command = [ self.namespace, resolved_method ].compact.join(":")
banner = (help) || command
Zillabyte::Command.register_command(
:klass => self,
:method => method,
:namespace => self.namespace,
:command => command,
:banner => banner.strip,
:help => help.join("\n"),
:summary => (help),
:description => (help),
:options => (help)
)
alias_command command.gsub(/_/, '-'), command if command =~ /_/
end
|
.namespace ⇒ Object
12
13
14
|
# File 'lib/zillabyte/cli/base.rb', line 12
def self.namespace
self.to_s.split("::").last.downcase
end
|