sdbcli 0.2.1 → 0.2.2
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.
- data/README +3 -3
- data/bin/sdbcli +78 -29
- metadata +5 -7
data/README
CHANGED
@@ -13,7 +13,7 @@ https://bitbucket.org/winebarrel/sdbcli
|
|
13
13
|
shell> gem install sdbcli
|
14
14
|
shell> export AWS_ACCESS_KEY_ID='...'
|
15
15
|
shell> export AWS_SECRET_ACCESS_KEY='...'
|
16
|
-
shell> export SDB_ENDPOINT='sdb.ap-northeast-1.amazonaws.com'
|
16
|
+
shell> export SDB_ENDPOINT='sdb.ap-northeast-1.amazonaws.com' # or REGION_NAME=ap-northeast-1
|
17
17
|
shell> sdbcli
|
18
18
|
|
19
19
|
== Example
|
@@ -43,12 +43,12 @@ https://bitbucket.org/winebarrel/sdbcli
|
|
43
43
|
SELECT output_list FROM domain_name [where expression] [sort_instructions] [limit limit]
|
44
44
|
queries using the SELECT statement
|
45
45
|
|
46
|
-
ap-northeast-1> select * from test
|
46
|
+
ap-northeast-1> select * from test;
|
47
47
|
---
|
48
48
|
- [itemname1, {attr1: val1, attr2: val2}]
|
49
49
|
- [itemname2, {attr1: val1, attr2: val2}]
|
50
50
|
|
51
|
-
ap-northeast-1> select * from `test-2
|
51
|
+
ap-northeast-1> select * from `test-2`;
|
52
52
|
---
|
53
53
|
- [itemname1, {attr1: val1, attr2: val2}]
|
54
54
|
- [itemname2, {attr1: val1, attr2: val2}]
|
data/bin/sdbcli
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$LOAD_PATH << File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')
|
3
3
|
|
4
|
-
Version = '0.2.
|
4
|
+
Version = '0.2.2'
|
5
5
|
HISTORY_FILE = File.join((ENV['HOME'] || ENV['USERPROFILE'] || '.'), '.sdbcli_history')
|
6
6
|
|
7
7
|
require 'rubygems'
|
@@ -9,11 +9,16 @@ require 'sdbcli'
|
|
9
9
|
|
10
10
|
require 'optparse'
|
11
11
|
require 'readline'
|
12
|
+
require 'strscan'
|
12
13
|
require 'yaml'
|
13
14
|
|
14
15
|
access_key_id = ENV['AWS_ACCESS_KEY_ID']
|
15
16
|
secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
|
16
|
-
sdb_endpoint = ENV['SDB_ENDPOINT'] || 'sdb.amazonaws.com'
|
17
|
+
sdb_endpoint = ENV['SDB_ENDPOINT'] || ENV['REGION_NAME'] || 'sdb.amazonaws.com'
|
18
|
+
|
19
|
+
if /\A[^.]+\Z/ =~ sdb_endpoint
|
20
|
+
sdb_endpoint = "sdb.#{sdb_endpoint}.amazonaws.com"
|
21
|
+
end
|
17
22
|
|
18
23
|
ARGV.options do |opt|
|
19
24
|
opt.on('-k', '--access-key=ACCESS_KEY') {|v| access_key_id = v }
|
@@ -29,33 +34,59 @@ end
|
|
29
34
|
|
30
35
|
$runner = SimpleDB::Runner.new(access_key_id, secret_access_key, sdb_endpoint)
|
31
36
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
37
|
+
def output_error(msg)
|
38
|
+
$stderr.puts "ERROR: #{msg}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def execute(src)
|
42
|
+
ss = StringScanner.new(src.dup)
|
35
43
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
44
|
+
while query = ss.scan_until(/(?:;|\\G)/i)
|
45
|
+
src.replace(ss.rest.strip)
|
46
|
+
query.strip!
|
47
|
+
|
48
|
+
if query =~ /\s*\\G\Z/i
|
49
|
+
query = query.sub(/\s*\\G\Z/i, '')
|
50
|
+
inline = false
|
51
|
+
else
|
52
|
+
query = query.strip.sub(/\s*;\Z/, '')
|
53
|
+
inline = true
|
54
|
+
end
|
55
|
+
|
56
|
+
if query.empty?
|
57
|
+
output_error('No query specified')
|
58
|
+
next
|
59
|
+
end
|
40
60
|
|
41
|
-
|
61
|
+
out = $runner.execute(query, inline)
|
42
62
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
63
|
+
if out
|
64
|
+
out = YAML.dump(out)
|
65
|
+
out << "\n" unless out =~ /\n\n\Z/
|
66
|
+
puts out
|
67
|
+
end
|
47
68
|
end
|
69
|
+
|
70
|
+
ss.rest.strip
|
48
71
|
end
|
49
72
|
|
50
73
|
unless $stdin.tty?
|
51
|
-
|
74
|
+
src = $stdin.read.strip
|
52
75
|
|
53
|
-
|
54
|
-
|
55
|
-
execute(query)
|
76
|
+
unless src =~ /\s*(?:;|\\G)\Z/i
|
77
|
+
src << ';'
|
56
78
|
end
|
57
79
|
|
58
|
-
|
80
|
+
begin
|
81
|
+
execute(src)
|
82
|
+
exit 0
|
83
|
+
rescue Racc::ParseError
|
84
|
+
output_error 'Parse error'
|
85
|
+
exit 1
|
86
|
+
rescue => e
|
87
|
+
output_error e.message.strip
|
88
|
+
exit 1
|
89
|
+
end
|
59
90
|
end
|
60
91
|
|
61
92
|
def help
|
@@ -98,7 +129,7 @@ end
|
|
98
129
|
|
99
130
|
at_exit do
|
100
131
|
unless Readline::HISTORY.empty?
|
101
|
-
open(HISTORY_FILE, '
|
132
|
+
open(HISTORY_FILE, 'wb') do |f|
|
102
133
|
Readline::HISTORY.each do |line|
|
103
134
|
next if /\A\s*\Z/ =~ line
|
104
135
|
f.puts line
|
@@ -107,24 +138,42 @@ at_exit do
|
|
107
138
|
end
|
108
139
|
end
|
109
140
|
|
110
|
-
|
141
|
+
src = ''
|
142
|
+
region = $runner.region || 'unknown'
|
143
|
+
prompt1 = "#{region}> "
|
144
|
+
prompt2 = "#{' ' * (region.length - 1)}-> "
|
145
|
+
prompt = prompt1
|
146
|
+
|
147
|
+
while buf = Readline.readline(prompt, true)
|
111
148
|
if /\A\s*\Z/ =~ buf
|
112
149
|
Readline::HISTORY.pop
|
113
150
|
next
|
114
151
|
end
|
115
152
|
|
116
|
-
|
117
|
-
|
118
|
-
|
153
|
+
if src.empty? and buf =~ /\A\.(.+)/
|
154
|
+
r = /\A#{Regexp.compile($1.downcase)}/
|
155
|
+
|
156
|
+
if r =~ 'help'
|
119
157
|
puts help
|
120
|
-
|
158
|
+
elsif r =~ 'exit' or r =~ 'quit'
|
121
159
|
exit
|
122
|
-
|
160
|
+
elsif r =~ 'version'
|
123
161
|
puts "sdbcli #{Version}"
|
124
162
|
else
|
125
|
-
|
163
|
+
output_error('Unknown command')
|
126
164
|
end
|
127
|
-
|
128
|
-
|
165
|
+
else
|
166
|
+
rv = nil
|
167
|
+
|
168
|
+
begin
|
169
|
+
src << (' ' + buf)
|
170
|
+
execute(src)
|
171
|
+
rescue Racc::ParseError
|
172
|
+
output_error 'Parse error'
|
173
|
+
rescue => e
|
174
|
+
output_error e.message.strip
|
175
|
+
end
|
176
|
+
|
177
|
+
prompt = src.empty? ? prompt1 : prompt2
|
129
178
|
end
|
130
179
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sdbcli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- winebarrel
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
18
|
+
date: 2013-01-17 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: nokogiri
|
@@ -49,7 +48,6 @@ files:
|
|
49
48
|
- lib/sdbcli/sdb-parser.y
|
50
49
|
- lib/sdbcli/sdb-runner.rb
|
51
50
|
- lib/sdbcli.rb
|
52
|
-
has_rdoc: true
|
53
51
|
homepage: https://bitbucket.org/winebarrel/sdbcli
|
54
52
|
licenses: []
|
55
53
|
|
@@ -79,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
77
|
requirements: []
|
80
78
|
|
81
79
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.
|
80
|
+
rubygems_version: 1.8.24
|
83
81
|
signing_key:
|
84
82
|
specification_version: 3
|
85
83
|
summary: sdbcli is an interactive command-line client of Amazon SimpleDB.
|