vzcdn 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -1
- data/bin/ec +13 -16
- data/bin/vzcdn +13 -16
- data/lib/args.rb +151 -120
- data/lib/argtest.rb +29 -0
- data/lib/cloptions.rb +53 -59
- data/lib/clui_config.rb +70 -31
- data/lib/command.rb +126 -0
- data/lib/common.rb +1 -0
- data/lib/config_handler.rb +5 -11
- data/lib/config_reader.rb +13 -2
- data/lib/makeBind.sh +90 -0
- data/lib/method.rb +5 -0
- data/lib/print.rb +270 -0
- data/lib/route.rb +10 -7
- data/lib/test_options.rb +16 -0
- data/lib/util.rb +10 -0
- data/lib/vzcdn.rb +31 -14
- data/lib/vzcdn/version.rb +1 -1
- data/lib/zone.rb +173 -97
- data/test/test_all.rb +2 -0
- data/test/test_reporting.rb +142 -0
- metadata +12 -3
- data/lib/command_proc.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea3992e358c4d3ae986c6034772689c8f179bed3
|
4
|
+
data.tar.gz: 5ae5616ae6c38ba917b5385a2e886c5932743d4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dbc5bef2dfd8f9f36008e5e39af44822168a68d22e8ec79faf247a5247fdf2b9640237a78f7771b61b4171c626661c839aa115f197f343e84d852b0cbb37b05
|
7
|
+
data.tar.gz: 2420c36df9dec21484824c3097dcf44ea5ea3a8a43f46d7f1305101e8faa4306018c97d5d52a509b6b30c8d93b70a2622b40cc8f1c779262c5219264fb36bc7e
|
data/README.md
CHANGED
@@ -3,9 +3,22 @@
|
|
3
3
|
Commandline UI for Edgecast API
|
4
4
|
|
5
5
|
##RELEASE NOTES
|
6
|
+
|
7
|
+
2014/04/09 0.1.5
|
8
|
+
* Default action - print
|
9
|
+
* Presentation changes for zone display ( <object> to "...", array elements to [num] etc)
|
10
|
+
* Column customization in display
|
11
|
+
* directory structure changes
|
12
|
+
* improved help
|
13
|
+
|
6
14
|
2014/04/09 0.1.4
|
7
|
-
|
15
|
+
* Bug fix for "ec zone <id> pull"
|
8
16
|
|
17
|
+
2014/04/08 0.1.3
|
18
|
+
* Enabled command "ec zone <id> pull"
|
19
|
+
* Supported command "ec zone <id> push"
|
20
|
+
* Abbreviation support for "ec zone <id> print"
|
21
|
+
* Support for option '-j' for "ec zone <id> print"
|
9
22
|
|
10
23
|
## Installation
|
11
24
|
|
data/bin/ec
CHANGED
@@ -1,31 +1,28 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'vzcdn'
|
4
|
-
require 'vzcdn/version'
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
def add_prefix(prefix, text)
|
6
|
+
result = ""
|
7
|
+
text.each_line { |line|
|
8
|
+
result = result + prefix + line
|
9
|
+
}
|
10
|
+
result
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
$debug
|
15
|
-
|
13
|
+
def dputs(*args)
|
14
|
+
if $debug
|
15
|
+
puts *args
|
16
|
+
end
|
16
17
|
end
|
17
18
|
|
18
|
-
args = []
|
19
|
-
ARGV.each { |arg|
|
20
|
-
args << arg
|
21
|
-
}
|
22
|
-
|
23
19
|
begin
|
24
|
-
VzcdnApp.
|
20
|
+
VzcdnApp.new("vzcdn", "vzcdn").run(ARGV)
|
21
|
+
|
25
22
|
exit 0
|
26
23
|
rescue Exception => e
|
27
24
|
if e.class != SystemExit
|
28
|
-
puts "ERROR:"
|
25
|
+
puts add_prefix("ERROR:", e.message)
|
29
26
|
if $debug
|
30
27
|
raise e
|
31
28
|
else
|
data/bin/vzcdn
CHANGED
@@ -1,31 +1,28 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'vzcdn'
|
4
|
-
require 'vzcdn/version'
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
def add_prefix(prefix, text)
|
6
|
+
result = ""
|
7
|
+
text.each_line { |line|
|
8
|
+
result = result + prefix + line
|
9
|
+
}
|
10
|
+
result
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
$debug
|
15
|
-
|
13
|
+
def dputs(*args)
|
14
|
+
if $debug
|
15
|
+
puts *args
|
16
|
+
end
|
16
17
|
end
|
17
18
|
|
18
|
-
args = []
|
19
|
-
ARGV.each { |arg|
|
20
|
-
args << arg
|
21
|
-
}
|
22
|
-
|
23
19
|
begin
|
24
|
-
VzcdnApp.
|
20
|
+
VzcdnApp.new("vzcdn", "vzcdn").run(ARGV)
|
21
|
+
|
25
22
|
exit 0
|
26
23
|
rescue Exception => e
|
27
24
|
if e.class != SystemExit
|
28
|
-
puts "ERROR:"
|
25
|
+
puts add_prefix("ERROR:", e.message)
|
29
26
|
if $debug
|
30
27
|
raise e
|
31
28
|
else
|
data/lib/args.rb
CHANGED
@@ -1,17 +1,38 @@
|
|
1
1
|
require_relative 'route'
|
2
2
|
|
3
3
|
class Arg
|
4
|
-
attr_accessor :desc, :required, :default, :validator, :name, :next_node, :
|
4
|
+
attr_accessor :desc, :required, :default, :validator, :name, :next_node, :repeatable
|
5
|
+
attr_reader :value
|
5
6
|
|
6
7
|
def initialize(name, hash={ })
|
7
8
|
@name = name
|
8
9
|
hash.each {|k,v| instance_variable_set("@#{k}",v)}
|
10
|
+
if @repeatable
|
11
|
+
@full = false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def full?
|
16
|
+
if @repeatable
|
17
|
+
@full
|
18
|
+
else
|
19
|
+
! @value.nil?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def value=(value)
|
24
|
+
if @repeatable
|
25
|
+
@value = [ ] if @value.nil?
|
26
|
+
@value << value
|
27
|
+
else
|
28
|
+
@value = value
|
29
|
+
end
|
9
30
|
end
|
10
31
|
|
11
32
|
# return true on success
|
12
33
|
# error message on failure
|
13
34
|
|
14
|
-
def validate?(value)
|
35
|
+
def validate?(value, obj)
|
15
36
|
vclass = @validator.class
|
16
37
|
if vclass == Regexp
|
17
38
|
test = (value =~ @validator)
|
@@ -28,68 +49,34 @@ class Arg
|
|
28
49
|
result[hash["Name"]] = hash["Id"]
|
29
50
|
}
|
30
51
|
@validator = result
|
31
|
-
test = validate?
|
52
|
+
test = validate?(value, obj)
|
32
53
|
if (test.class == String)
|
33
54
|
on_error = test
|
34
55
|
test = false
|
35
56
|
end
|
57
|
+
elsif vclass == Symbol
|
58
|
+
on_error, test = obj.send(@validator, value)
|
36
59
|
else
|
37
60
|
test = false
|
38
61
|
on_error = "unknown type of validator:" + @validator.to_s + ", class=" + @validator.class.to_s
|
39
62
|
end
|
63
|
+
if not test && @repeatable
|
64
|
+
@full = true
|
65
|
+
end
|
40
66
|
if test
|
41
|
-
|
67
|
+
nil
|
42
68
|
else
|
43
69
|
on_error
|
44
70
|
end
|
45
71
|
end
|
46
72
|
end
|
47
73
|
|
48
|
-
class Decision
|
49
|
-
attr_accessor :flow
|
50
|
-
|
51
|
-
def initialize(decider, *symbols)
|
52
|
-
@decider = decider
|
53
|
-
@tree = { }
|
54
|
-
symbols.each { |symbol|
|
55
|
-
@tree[symbol] = Flow.new(nil)
|
56
|
-
}
|
57
|
-
end
|
58
|
-
|
59
|
-
def chosen
|
60
|
-
vars = @flow.find(self)
|
61
|
-
arr = @decider.decide(vars, @tree.keys).map { |symbol|
|
62
|
-
@tree[symbol].root
|
63
|
-
}
|
64
|
-
arr
|
65
|
-
end
|
66
|
-
|
67
|
-
def children
|
68
|
-
@tree.values
|
69
|
-
end
|
70
|
-
|
71
|
-
def add(child, arg)
|
72
|
-
@tree[child].add arg
|
73
|
-
end
|
74
|
-
|
75
|
-
def to_s
|
76
|
-
result = "branch names:"
|
77
|
-
@tree.keys.each { |child|
|
78
|
-
result = result + child.to_s + " "
|
79
|
-
}
|
80
|
-
result += "\nbranches are of classes:"
|
81
|
-
@tree.keys.each { |child|
|
82
|
-
result = result + @tree[child].class.to_s + " "
|
83
|
-
}
|
84
|
-
result
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
74
|
class Flow
|
89
|
-
attr_reader :root
|
75
|
+
attr_reader :root, :command
|
90
76
|
|
91
|
-
def initialize(
|
92
|
-
@root =
|
77
|
+
def initialize(*args)
|
78
|
+
@root = nil
|
79
|
+
add(*args)
|
93
80
|
end
|
94
81
|
|
95
82
|
def iargs(node, args)
|
@@ -103,85 +90,71 @@ class Flow
|
|
103
90
|
args = new_args
|
104
91
|
end
|
105
92
|
iargs(node.next_node, args)
|
106
|
-
elsif
|
107
|
-
|
108
|
-
|
109
|
-
}
|
93
|
+
elsif node.is_a? Command
|
94
|
+
args["command"] = node
|
95
|
+
return args
|
110
96
|
end
|
111
97
|
end
|
112
98
|
|
113
|
-
def
|
99
|
+
def args
|
100
|
+
iargs(@root, {})
|
101
|
+
end
|
102
|
+
|
103
|
+
def validate_and_set(value, node)
|
104
|
+
response = node.validate?(value, @target)
|
105
|
+
if response.nil?
|
106
|
+
node.value = value
|
107
|
+
end
|
108
|
+
response
|
109
|
+
end
|
110
|
+
|
111
|
+
def isetvalue(value, node)
|
114
112
|
if node.nil?
|
115
|
-
return nil
|
113
|
+
return nil, :finished
|
116
114
|
end
|
117
|
-
if
|
118
|
-
return
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
115
|
+
if node.full?
|
116
|
+
return isetvalue(value, node.next_node)
|
117
|
+
end
|
118
|
+
if node.class == Arg
|
119
|
+
error = validate_and_set(value, node)
|
120
|
+
if error && node.repeatable
|
121
|
+
return isetvalue(value, node.next_node)
|
122
|
+
else
|
123
|
+
return error, nil
|
124
|
+
end
|
125
|
+
elsif node.is_a? Command
|
126
|
+
if value == node.name.to_s
|
127
|
+
node.setfull
|
128
|
+
return nil, nil
|
129
|
+
else
|
130
|
+
return "incorrect command name", nil
|
124
131
|
end
|
125
|
-
ifind(elt, node.next_node, args)
|
126
|
-
elsif (node.class == Decision)
|
127
|
-
found = false
|
128
|
-
node.children.each { |child|
|
129
|
-
result = ifind(elt, child, args)
|
130
|
-
if (result)
|
131
|
-
return result
|
132
|
-
end
|
133
|
-
}
|
134
|
-
return nil
|
135
132
|
end
|
136
133
|
end
|
137
|
-
|
138
134
|
|
139
|
-
def
|
140
|
-
|
135
|
+
def setvalue(value)
|
136
|
+
isetvalue(value, @root)
|
141
137
|
end
|
142
138
|
|
143
|
-
# return true for success
|
144
|
-
# false for unable to find arg name
|
145
|
-
# String for invalid arg
|
146
|
-
|
147
139
|
def iset(name, value, node)
|
148
140
|
if node.nil?
|
149
|
-
return
|
141
|
+
return "could not find argument with name #{name}", :finished
|
150
142
|
end
|
151
143
|
if (node.class == Arg )
|
152
144
|
if (node.name == name)
|
153
|
-
|
154
|
-
|
155
|
-
return response
|
156
|
-
else
|
157
|
-
node.value = value
|
158
|
-
return true
|
159
|
-
end
|
145
|
+
error = validate_and_set(value, node)
|
146
|
+
return error, nil
|
160
147
|
else
|
161
|
-
iset(name, value, node.next_node)
|
148
|
+
return iset(name, value, node.next_node)
|
162
149
|
end
|
163
|
-
|
164
|
-
result = false
|
165
|
-
node.children.each { |flow|
|
166
|
-
response = iset(name, value, flow.root)
|
167
|
-
if (response == true)
|
168
|
-
result = true
|
169
|
-
elsif (response.class == String)
|
170
|
-
return response
|
171
|
-
end
|
172
|
-
}
|
173
|
-
result
|
174
|
-
end
|
150
|
+
end
|
175
151
|
end
|
176
152
|
|
153
|
+
# return true for success
|
154
|
+
# false for unable to find arg name
|
155
|
+
# String for invalid arg
|
177
156
|
def set(name, value)
|
178
|
-
|
179
|
-
if (response == false)
|
180
|
-
puts "ERROR: could not find argument with name " + name
|
181
|
-
elsif (response.class == String)
|
182
|
-
puts "ERROR: " + response
|
183
|
-
end
|
184
|
-
response
|
157
|
+
iset(name, value, @root)
|
185
158
|
end
|
186
159
|
|
187
160
|
def iadd(arg, node)
|
@@ -192,19 +165,24 @@ class Flow
|
|
192
165
|
end
|
193
166
|
end
|
194
167
|
|
195
|
-
def add(
|
168
|
+
def add(*args)
|
169
|
+
return if args.length == 0
|
196
170
|
if @root.nil?
|
197
|
-
@root =
|
198
|
-
else
|
199
|
-
iadd(arg, @root)
|
171
|
+
@root = args.shift
|
200
172
|
end
|
173
|
+
args.each { |arg|
|
174
|
+
iadd(arg, @root)
|
175
|
+
}
|
176
|
+
self
|
201
177
|
end
|
202
178
|
|
203
179
|
def to_s
|
180
|
+
result = ""
|
204
181
|
args = iargs(@root, {})
|
205
182
|
args.each { |name, value|
|
206
|
-
|
183
|
+
result = result + "\n#{name}:#{value}"
|
207
184
|
}
|
185
|
+
result
|
208
186
|
end
|
209
187
|
|
210
188
|
def print_flow(node)
|
@@ -219,20 +197,73 @@ class Flow
|
|
219
197
|
print_flow(node.next_node)
|
220
198
|
end
|
221
199
|
|
222
|
-
def
|
223
|
-
|
224
|
-
if (
|
225
|
-
|
200
|
+
def iusage(node, names, desc)
|
201
|
+
return names, desc if node.nil?
|
202
|
+
if node.class == Arg || node.is_a?(Command)
|
203
|
+
names << (node.class == Arg ? "<#{node.name}>" : node.name)
|
204
|
+
desc << node.desc
|
205
|
+
iusage node.next_node, names, desc
|
206
|
+
end
|
207
|
+
return names, desc
|
208
|
+
end
|
209
|
+
|
210
|
+
def usage
|
211
|
+
names, desc = iusage root, [ ], [ ]
|
212
|
+
end
|
213
|
+
|
214
|
+
def ivalidate(node, missing)
|
215
|
+
return missing if node.nil?
|
216
|
+
if node.class == Arg
|
217
|
+
if (node.required) && (node.value.nil?)
|
218
|
+
missing << node.name
|
219
|
+
end
|
220
|
+
ivalidate node.next_node, missing
|
221
|
+
elsif node.is_a? Command
|
222
|
+
if node.required? && (not node.full?)
|
223
|
+
missing << node.name
|
224
|
+
end
|
225
|
+
end
|
226
|
+
missing
|
227
|
+
end
|
228
|
+
|
229
|
+
def validate
|
230
|
+
ivalidate root, [ ]
|
231
|
+
end
|
232
|
+
|
233
|
+
def add_errline(str, error)
|
234
|
+
if str
|
235
|
+
str + "\n" + error
|
226
236
|
else
|
227
|
-
|
237
|
+
error
|
228
238
|
end
|
229
239
|
end
|
230
240
|
|
231
|
-
def parse(args)
|
232
|
-
|
233
|
-
|
234
|
-
|
241
|
+
def parse(args, obj = nil)
|
242
|
+
result = nil
|
243
|
+
rest = [ ]
|
244
|
+
@target = obj
|
245
|
+
args.each_with_index { |arg, index|
|
246
|
+
name, value = Util.parse_line(arg)
|
247
|
+
if value.nil?
|
248
|
+
value = name
|
249
|
+
error, finished = setvalue(value)
|
250
|
+
else
|
251
|
+
error, finished = set(name, value)
|
252
|
+
end
|
253
|
+
|
254
|
+
if error
|
255
|
+
result = add_errline(result, error)
|
256
|
+
finished = :finished
|
257
|
+
end
|
258
|
+
if finished
|
259
|
+
rest = args[index...args.length]
|
260
|
+
break
|
261
|
+
end
|
235
262
|
}
|
263
|
+
missing = validate
|
264
|
+
if ! missing.empty?
|
265
|
+
result = add_errline(result, "missing args:" + missing.to_s)
|
266
|
+
end
|
267
|
+
return result, rest
|
236
268
|
end
|
237
|
-
|
238
269
|
end
|