ec2cli 0.1.0

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.
@@ -0,0 +1,233 @@
1
+ class Parser
2
+ options no_result_var
3
+ rule
4
+ stmt : describe_stmt
5
+ | run_stmt
6
+ | start_stmt
7
+ | stop_stmt
8
+ | set_stmt
9
+ | show_stmt
10
+ | use_stmt
11
+
12
+ describe_stmt : describe_or_desc INSTANCES where_clause
13
+ {
14
+ struct(:DESCRIBE_INSTANCES, :filter => val[2])
15
+ }
16
+ | describe_or_desc IMAGES where_clause
17
+ {
18
+ struct(:DESCRIBE_IMAGES, :filter => val[2], :all => false)
19
+ }
20
+ | describe_or_desc ALL IMAGES where_clause
21
+ {
22
+ struct(:DESCRIBE_IMAGES, :filter => val[3], :all => true)
23
+ }
24
+
25
+ describe_or_desc : DESCRIBE | DESC
26
+
27
+ where_clause :
28
+ | WHERE expr_list
29
+ {
30
+ val[1]
31
+ }
32
+
33
+ expr_list : expr
34
+ {
35
+ [val[0]]
36
+ }
37
+ | expr_list AND expr
38
+ {
39
+ val[0] + [val[2]]
40
+ }
41
+
42
+ expr : IDENTIFIER EQ value
43
+ {
44
+ [val[0], [val[2]]]
45
+ }
46
+ | IDENTIFIER EQ value_list
47
+ {
48
+ [val[0], val[2]]
49
+ }
50
+
51
+ run_stmt : RUN INSTANCES value
52
+ {
53
+ struct(:RUN_INSTANCES, :image_id => val[2])
54
+ }
55
+
56
+ start_stmt : START INSTANCES value
57
+ {
58
+ struct(:START_INSTANCES, :instances => [val[2]])
59
+ }
60
+ | START INSTANCES value_list
61
+ {
62
+ struct(:START_INSTANCES, :instances => val[2])
63
+ }
64
+
65
+ stop_stmt : STOP INSTANCES value
66
+ {
67
+ struct(:STOP_INSTANCES, :instances => [val[2]])
68
+ }
69
+ | STOP INSTANCES value_list
70
+ {
71
+ struct(:STOP_INSTANCES, :instances => val[2])
72
+ }
73
+
74
+ set_stmt : SET TAGS attr_list where_clause
75
+ {
76
+ struct(:CREATE_TAGS, :tags => val[2], :filter => val[3])
77
+ }
78
+
79
+ attr_list : attr
80
+ {
81
+ [val[0]]
82
+ }
83
+ | attr_list ',' attr
84
+ {
85
+ val[0] + [val[2]]
86
+ }
87
+
88
+ attr : IDENTIFIER EQ value
89
+ {
90
+ [val[0], val[2]]
91
+ }
92
+ | IDENTIFIER EQ NULL
93
+ {
94
+ [val[0], nil]
95
+ }
96
+
97
+ show_stmt : SHOW REGIONS
98
+ {
99
+ struct(:SHOW_REGIONS)
100
+ }
101
+
102
+ use_stmt : USE IDENTIFIER
103
+ {
104
+ struct(:USE, :endpoint_or_region => val[1])
105
+ }
106
+
107
+ value : STRING | NUMBER
108
+
109
+ value_list : '(' number_list ')'
110
+ {
111
+ val[1]
112
+ }
113
+ | '(' string_list ')'
114
+ {
115
+ val[1]
116
+ }
117
+
118
+ number_list : NUMBER
119
+ {
120
+ [val[0]]
121
+ }
122
+ | number_list ',' NUMBER
123
+ {
124
+ val[0] + [val[2]]
125
+ }
126
+
127
+ string_list : STRING
128
+ {
129
+ [val[0]]
130
+ }
131
+ | string_list ',' STRING
132
+ {
133
+ val[0] + [val[2]]
134
+ }
135
+
136
+ ---- header
137
+
138
+ require 'strscan'
139
+
140
+ module EC2
141
+
142
+ ---- inner
143
+
144
+ KEYWORDS = %w(
145
+ ALL
146
+ AND
147
+ DESCRIBE
148
+ DESC
149
+ IMAGES
150
+ INSTANCES
151
+ REGIONS
152
+ RUN
153
+ SET
154
+ SHOW
155
+ START
156
+ STOP
157
+ TAGS
158
+ USE
159
+ WHERE
160
+ )
161
+
162
+ KEYWORD_REGEXP = Regexp.compile("(?:#{KEYWORDS.join '|'})\\b", Regexp::IGNORECASE)
163
+
164
+ def initialize(obj)
165
+ src = obj.is_a?(IO) ? obj.read : obj.to_s
166
+ @ss = StringScanner.new(src)
167
+ end
168
+
169
+ @@structs = {}
170
+
171
+ def struct(name, attrs = {})
172
+ unless (clazz = @@structs[name])
173
+ clazz = attrs.empty? ? Struct.new(name.to_s) : Struct.new(name.to_s, *attrs.keys)
174
+ @@structs[name] = clazz
175
+ end
176
+
177
+ obj = clazz.new
178
+
179
+ attrs.each do |key, val|
180
+ obj.send("#{key}=", val)
181
+ end
182
+
183
+ return obj
184
+ end
185
+ private :struct
186
+
187
+ def scan
188
+ tok = nil
189
+
190
+ until @ss.eos?
191
+ if (tok = @ss.scan /\s+/)
192
+ # nothing to do
193
+ elsif (tok = @ss.scan /(?:=)/)
194
+ sym = {
195
+ '=' => :EQ,
196
+ }.fetch(tok)
197
+ yield [sym, tok]
198
+ elsif (tok = @ss.scan KEYWORD_REGEXP)
199
+ yield [tok.upcase.to_sym, tok]
200
+ elsif (tok = @ss.scan /NULL/i)
201
+ yield [:NULL, nil]
202
+ elsif (tok = @ss.scan /`(?:[^`]|``)*`/)
203
+ yield [:IDENTIFIER, tok.slice(1...-1).gsub(/``/, '`')]
204
+ elsif (tok = @ss.scan /'(?:[^']|'')*'/) #'
205
+ yield [:STRING, tok.slice(1...-1).gsub(/''/, "'")]
206
+ elsif (tok = @ss.scan /"(?:[^"]|"")*"/) #"
207
+ yield [:STRING, tok.slice(1...-1).gsub(/""/, '"')]
208
+ elsif (tok = @ss.scan /\d+(?:\.\d+)?/)
209
+ yield [:NUMBER, (tok =~ /\./ ? tok.to_f : tok.to_i)]
210
+ elsif (tok = @ss.scan /[,\(\)\*]/)
211
+ yield [tok, tok]
212
+ elsif (tok = @ss.scan /[^\s]+/)
213
+ yield [:IDENTIFIER, tok]
214
+ else
215
+ raise Racc::ParseError, ('parse error on value "%s"' % @ss.rest.inspect)
216
+ end
217
+ end
218
+
219
+ yield [false, 'EOF']
220
+ end
221
+ private :scan
222
+
223
+ def parse
224
+ yyparse self, :scan
225
+ end
226
+
227
+ def self.parse(obj)
228
+ self.new(obj).parse
229
+ end
230
+
231
+ ---- footer
232
+
233
+ end # EC2
data/lib/ec2cli.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'ec2cli/ec2-client'
2
+ require 'ec2cli/ec2-driver'
3
+ require 'ec2cli/ec2-endpoint'
4
+ require 'ec2cli/ec2-error'
5
+ require 'ec2cli/ec2-parser.tab'
6
+
7
+ # CLI
8
+ require 'ec2cli/cli/evaluate'
9
+ require 'ec2cli/cli/functions'
10
+ require 'ec2cli/cli/help'
11
+ require 'ec2cli/cli/options'
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ec2cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - winebarrel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description:
31
+ email: sgwr_dts@yahoo.co.jp
32
+ executables:
33
+ - ec2cli
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - README
38
+ - bin/ec2cli
39
+ - lib/ec2cli/cli/evaluate.rb
40
+ - lib/ec2cli/cli/functions.rb
41
+ - lib/ec2cli/cli/help.rb
42
+ - lib/ec2cli/cli/options.rb
43
+ - lib/ec2cli/ec2-client.rb
44
+ - lib/ec2cli/ec2-driver.rb
45
+ - lib/ec2cli/ec2-endpoint.rb
46
+ - lib/ec2cli/ec2-error.rb
47
+ - lib/ec2cli/ec2-parser.tab.rb
48
+ - lib/ec2cli/ec2-parser.y
49
+ - lib/ec2cli.rb
50
+ homepage: https://bitbucket.org/winebarrel/ec2cli
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.23
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: ec2cli is an interactive command-line client of Amazon EC2.
74
+ test_files: []