elasticshell 0.0.4 → 0.0.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.
- data/README.rdoc +8 -5
- data/VERSION +1 -1
- data/bin/es +1 -0
- data/lib/elasticshell.rb +4 -44
- data/lib/elasticshell/client.rb +20 -9
- data/lib/elasticshell/command.rb +2 -2
- data/lib/elasticshell/commands/connect.rb +18 -6
- data/lib/elasticshell/commands/exit.rb +15 -0
- data/lib/elasticshell/commands/ls.rb +4 -4
- data/lib/elasticshell/commands/request_parser.rb +1 -1
- data/lib/elasticshell/runner.rb +58 -0
- data/lib/elasticshell/scopes/global.rb +2 -1
- data/lib/elasticshell/scopes/index.rb +1 -0
- data/lib/elasticshell/scopes/mapping.rb +1 -0
- data/lib/elasticshell/shell.rb +11 -19
- data/lib/elasticshell/utils.rb +1 -0
- data/lib/elasticshell/utils/es_config.rb +63 -0
- data/lib/elasticshell/utils/log.rb +79 -3
- data/spec/elasticshell/commands/cd_spec.rb +1 -1
- data/spec/elasticshell/commands/connect_spec.rb +1 -1
- data/spec/elasticshell/commands/request_spec.rb +1 -1
- metadata +6 -3
data/README.rdoc
CHANGED
@@ -244,11 +244,14 @@ that has the +response+ and +request+ variables in scope. You can be
|
|
244
244
|
even more free by just piping without any Ruby code, which will leave
|
245
245
|
you in a Ruby (Pry) shell with the same binding.
|
246
246
|
|
247
|
-
GET /my_index$ _search /tmp/query_that_needs_interaction.json |
|
248
|
-
>> response
|
249
|
-
=> {"took"=>1, "timed_out"=>false, ... }
|
250
|
-
>> request
|
251
|
-
=> {:verb=>"GET", :path=>"/_search", :query_options=>{}, :body=>""}
|
247
|
+
GET /my_index$ _search /tmp/query_that_needs_interaction.json |
|
248
|
+
>> response
|
249
|
+
=> {"took"=>1, "timed_out"=>false, ... }
|
250
|
+
>> request
|
251
|
+
=> {:verb=>"GET", :path=>"/_search", :query_options=>{}, :body=>""}
|
252
|
+
|
253
|
+
Hit CTRL-D to get out of this new interactive Ruby shell and back to
|
254
|
+
Elasticshell.
|
252
255
|
|
253
256
|
=== Requests from the command line
|
254
257
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/bin/es
CHANGED
data/lib/elasticshell.rb
CHANGED
@@ -4,24 +4,6 @@ require 'configliere'
|
|
4
4
|
|
5
5
|
require 'elasticshell/utils'
|
6
6
|
|
7
|
-
Settings.use(:commandline)
|
8
|
-
|
9
|
-
Settings.define(:servers, :description => "A comma-separated list of Elasticsearch servers to connect to.", :type => Array, :default => 'http://localhost:9200')
|
10
|
-
Settings.define(:only, :description => "A dot-separated hierarchical key to extract from the output scope.")
|
11
|
-
Settings.define(:pretty, :description => "Pretty-print all output. ", :default => false, :type => :boolean)
|
12
|
-
Settings.define(:verb, :description => "Set the default HTTP verb. ", :default => "GET")
|
13
|
-
Settings.define(:version, :description => "Print Elasticshell version and exit. ", :default => false, :type => :boolean)
|
14
|
-
Settings.define(:scope, :description => "The default scope to start the shell in.", :default => "/")
|
15
|
-
Settings.description = <<-DESC
|
16
|
-
Elasticshell is a command-line shell for interacting with an
|
17
|
-
Elasticsearch database. It has the following start-up options.
|
18
|
-
DESC
|
19
|
-
|
20
|
-
def Settings.usage
|
21
|
-
"usage: #{File.basename($0)} [OPTIONS] [REQUEST]"
|
22
|
-
end
|
23
|
-
Settings.resolve!
|
24
|
-
|
25
7
|
module Elasticshell
|
26
8
|
|
27
9
|
autoload :Client, 'elasticshell/client'
|
@@ -33,32 +15,10 @@ module Elasticshell
|
|
33
15
|
|
34
16
|
def self.version
|
35
17
|
@version ||= begin
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.start *args
|
43
|
-
begin
|
44
|
-
case
|
45
|
-
when Settings[:version]
|
46
|
-
puts version
|
47
|
-
exit()
|
48
|
-
when Settings[:only] && Settings.rest.empty?
|
49
|
-
raise ArgumentError.new("Starting with the --only option requires a request argument (like `/_cluster/health')")
|
50
|
-
exit(1)
|
51
|
-
when (! Settings.rest.empty?)
|
52
|
-
es = Shell.new(Settings.merge(:log_requests => false))
|
53
|
-
es.connect
|
54
|
-
es.eval_line(Settings.rest.first)
|
55
|
-
exit()
|
56
|
-
else
|
57
|
-
Shell.new(Settings).run
|
58
|
-
end
|
59
|
-
rescue Elasticshell::Error => e
|
60
|
-
$stderr.puts e.message
|
61
|
-
exit(2)
|
18
|
+
File.read(File.expand_path('../../VERSION', __FILE__)).chomp
|
19
|
+
rescue => e
|
20
|
+
'unknown'
|
62
21
|
end
|
63
22
|
end
|
23
|
+
|
64
24
|
end
|
data/lib/elasticshell/client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rubberband'
|
2
|
+
require 'timeout'
|
2
3
|
|
3
4
|
module Elasticshell
|
4
5
|
|
@@ -9,11 +10,21 @@ module Elasticshell
|
|
9
10
|
end
|
10
11
|
|
11
12
|
def connect options={}
|
12
|
-
servers = (options.merge(
|
13
|
+
servers = (@options.merge(options)[:servers] || Settings[:servers].to_s.split(","))
|
14
|
+
raise ClientError.new("Must provide at least one server to connect to.") if servers.empty?
|
13
15
|
begin
|
14
|
-
|
16
|
+
Elasticshell.debug("Connecting to Elasticsearch servers: #{servers.join(', ')}")
|
17
|
+
begin
|
18
|
+
timeout(5) do
|
19
|
+
@client = ElasticSearch::Client.new(servers)
|
20
|
+
end
|
21
|
+
rescue Timeout::Error => e
|
22
|
+
Elasticshell.error("Could not connect to Elasticsearch servers: #{servers.join(', ')}")
|
23
|
+
return
|
24
|
+
end
|
25
|
+
Elasticshell.info("Connected to Elasticsearch servers: #{servers.join(', ')}")
|
15
26
|
rescue ElasticSearch::ConnectionFailed => e
|
16
|
-
raise ClientError.new("Could not connect to Elasticsearch server
|
27
|
+
raise ClientError.new("Could not connect to Elasticsearch server: #{servers.join(', ')}")
|
17
28
|
end
|
18
29
|
end
|
19
30
|
|
@@ -45,16 +56,16 @@ module Elasticshell
|
|
45
56
|
end
|
46
57
|
|
47
58
|
def log_request verb, params, options={}
|
48
|
-
begin
|
59
|
+
# begin
|
49
60
|
# FIXME digging way too deep into rubberband here...is it really
|
50
|
-
|
61
|
+
# necessary?
|
51
62
|
uri = @client.instance_variable_get('@connection').send(:generate_uri, params)
|
52
63
|
query = @client.instance_variable_get('@connection').send(:generate_query_string, options)
|
53
64
|
path = [uri, query].reject { |s| s.nil? || s.strip.empty? }.join("?").gsub(Regexp.new("^/+"), "/")
|
54
|
-
Elasticshell.
|
55
|
-
rescue
|
56
|
-
|
57
|
-
end
|
65
|
+
Elasticshell.request(verb, @client.current_server, path)
|
66
|
+
# rescue
|
67
|
+
# Elasticshell.info(verb, path, "#{verb.to_s.upcase} #{params.inspect} #{options.inspect}".strip)
|
68
|
+
# end
|
58
69
|
end
|
59
70
|
|
60
71
|
def safely verb, params={}, options={}, body=''
|
data/lib/elasticshell/command.rb
CHANGED
@@ -14,7 +14,7 @@ module Elasticshell
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def be_connected!
|
17
|
-
raise ClientError.new("Not connected to any Elasticsearch servers.") unless shell.connected?
|
17
|
+
raise ClientError.new("Not connected to any Elasticsearch servers. Try running\n\n\t#{shell.prompt}connect URI [URI] ...\n\n") unless shell.connected?
|
18
18
|
end
|
19
19
|
|
20
20
|
def evaluate!
|
@@ -24,7 +24,7 @@ module Elasticshell
|
|
24
24
|
|
25
25
|
module Commands
|
26
26
|
PRIORITY = [].tap do |priority|
|
27
|
-
%w[cd pwd df connect help ls pretty set_verb blank request unknown].each do |command_name|
|
27
|
+
%w[cd pwd df connect help ls pretty set_verb exit blank request unknown].each do |command_name|
|
28
28
|
klass_name = command_name.split("_").map(&:capitalize).join("")
|
29
29
|
autoload klass_name.to_sym, "elasticshell/commands/#{command_name}"
|
30
30
|
priority << klass_name
|
@@ -13,18 +13,30 @@ module Elasticshell
|
|
13
13
|
if servers.empty?
|
14
14
|
shell.client.connect()
|
15
15
|
else
|
16
|
-
servers.
|
16
|
+
uris = servers.map do |raw|
|
17
|
+
has_port = raw =~ /:\d+/
|
18
|
+
cooked = (raw =~ /^http:\/\// ? raw : 'http://' + raw)
|
19
|
+
cooked += '/' unless cooked =~ /\/$/
|
17
20
|
begin
|
18
|
-
uri = URI.parse(
|
21
|
+
uri = URI.parse(cooked)
|
22
|
+
if uri.path == '/'
|
23
|
+
uri.port = 9200 unless has_port
|
24
|
+
uri.to_s
|
25
|
+
else
|
26
|
+
Elasticshell.warn("#{raw} is not a valid URI for an ElasticSearch server")
|
27
|
+
nil
|
28
|
+
end
|
19
29
|
rescue => e
|
20
|
-
|
30
|
+
Elasticshell.warn("#{raw} is not a valid URI")
|
31
|
+
nil
|
21
32
|
end
|
22
|
-
|
23
|
-
|
24
|
-
shell.client.connect(:servers => servers)
|
33
|
+
end.compact
|
34
|
+
shell.client.connect(:servers => uris)
|
25
35
|
end
|
26
36
|
end
|
27
37
|
|
38
|
+
|
39
|
+
|
28
40
|
end
|
29
41
|
end
|
30
42
|
end
|
@@ -40,21 +40,21 @@ module Elasticshell
|
|
40
40
|
when scope.class == Scopes::Index && scope.mappings.include?(scope_name)
|
41
41
|
shell.print("m \e[32m%s\e[0m" % [scope_name])
|
42
42
|
else
|
43
|
-
shell.print
|
43
|
+
shell.print Elasticshell.format(:scope_long_format, "%s", scope_name)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
sort(scope.request_names).each do |request|
|
47
|
-
shell.print
|
47
|
+
shell.print Elasticshell.format(:request_long_format, "%r", request)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
def ls!
|
52
52
|
output = []
|
53
53
|
sort(scope.scopes).map do |scope|
|
54
|
-
output <<
|
54
|
+
output << Elasticshell.format(:scope_format, "%s", scope)
|
55
55
|
end
|
56
56
|
sort(scope.request_names).map do |request|
|
57
|
-
output <<
|
57
|
+
output << Elasticshell.format(:request_format, "%r", request)
|
58
58
|
end
|
59
59
|
shell.print output.join(' ')
|
60
60
|
end
|
@@ -60,7 +60,7 @@ module Elasticshell
|
|
60
60
|
when raw_body.nil?
|
61
61
|
''
|
62
62
|
when raw_body == '-'
|
63
|
-
|
63
|
+
Elasticshell.info("Reading request body from STDIN. Press `C-d' to terminate input...")
|
64
64
|
command.shell.input_stream.gets(nil)
|
65
65
|
when File.exist?(raw_body)
|
66
66
|
File.read(raw_body)
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Elasticshell
|
2
|
+
|
3
|
+
ORIG_ARGV = ARGV.dup.freeze
|
4
|
+
|
5
|
+
Settings.use(:commandline)
|
6
|
+
Settings.define(:servers, :description => "A comma-separated list of Elasticsearch servers to connect to.", :type => Array, :default => ['localhost:9200'])
|
7
|
+
Settings.define(:config, :description => "Path to an Elasticsearch config file to read settings from", :default => '/etc/elasticsearch/elasticsearch.yml')
|
8
|
+
Settings.define(:only, :description => "A dot-separated hierarchical key to extract from the output scope.")
|
9
|
+
Settings.define(:pretty, :description => "Pretty-print all output. ", :default => false, :type => :boolean)
|
10
|
+
Settings.define(:verb, :description => "Set the default HTTP verb. ", :default => "GET")
|
11
|
+
Settings.define(:version, :description => "Print Elasticshell version and exit. ", :default => false, :type => :boolean)
|
12
|
+
Settings.define(:scope, :description => "The default scope to start the shell in.", :default => "/")
|
13
|
+
Settings.define(:eval, :description => "Evaluate given Ruby code on response.")
|
14
|
+
Settings.description = <<-DESC
|
15
|
+
Elasticshell is a command-line shell for interacting with an
|
16
|
+
Elasticsearch database. It has the following start-up options.
|
17
|
+
DESC
|
18
|
+
|
19
|
+
def Settings.usage
|
20
|
+
"usage: #{File.basename($0)} [OPTIONS] [REQUEST]"
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.overrode_servers_on_command_line?
|
24
|
+
ORIG_ARGV.any? { |arg| arg =~ /--servers/ }
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.find_servers_from_config_file! path=nil
|
28
|
+
return if overrode_servers_on_command_line?
|
29
|
+
file = ElasticsearchConfigFile.new(path || Settings[:config])
|
30
|
+
Settings[:servers] = file.hosts if file.readable? && (!file.hosts.empty?)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.start *args
|
34
|
+
begin
|
35
|
+
Settings.resolve!
|
36
|
+
find_servers_from_config_file!
|
37
|
+
case
|
38
|
+
when Settings[:version]
|
39
|
+
puts version
|
40
|
+
exit()
|
41
|
+
when (Settings[:only] || Settings[:eval]) && Settings.rest.empty?
|
42
|
+
raise ArgumentError.new("Starting with the --only or --eval options requires a request argument (like `/_cluster/health')")
|
43
|
+
exit(1)
|
44
|
+
when (! Settings.rest.empty?)
|
45
|
+
es = Shell.new(Settings.merge(:log_requests => false))
|
46
|
+
es.connect
|
47
|
+
es.eval_line(Settings.rest.first)
|
48
|
+
exit()
|
49
|
+
else
|
50
|
+
Shell.new(Settings).run
|
51
|
+
end
|
52
|
+
rescue Elasticshell::Error => e
|
53
|
+
Elasticshell.error(e.message)
|
54
|
+
exit(2)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -14,7 +14,8 @@ module Elasticshell
|
|
14
14
|
def self.requests
|
15
15
|
@requests ||= {
|
16
16
|
"GET" => {
|
17
|
-
'_status' => "Retreive the status of all indices in the cluster."
|
17
|
+
'_status' => "Retreive the status of all indices in the cluster.",
|
18
|
+
'_count' => "Count all records."
|
18
19
|
}
|
19
20
|
}
|
20
21
|
end
|
data/lib/elasticshell/shell.rb
CHANGED
@@ -62,7 +62,7 @@ module Elasticshell
|
|
62
62
|
|
63
63
|
include Elasticshell::HasVerb
|
64
64
|
|
65
|
-
attr_accessor :client, :state, :only, :input, :cache, :output, :
|
65
|
+
attr_accessor :client, :state, :only, :ruby_code, :input, :cache, :output, :line, :input_stream
|
66
66
|
|
67
67
|
attr_reader :scope
|
68
68
|
def scope= scope
|
@@ -91,9 +91,9 @@ module Elasticshell
|
|
91
91
|
self.verb = (options[:verb] || 'GET')
|
92
92
|
self.scope = scope_from_path(options[:scope] || '/')
|
93
93
|
self.only = options[:only]
|
94
|
+
self.ruby_code = options[:eval]
|
94
95
|
self.input_stream = (options[:input] || $stdin)
|
95
96
|
self.output = (options[:output] || $stdout)
|
96
|
-
self.error = (options[:error] || $stderr)
|
97
97
|
self.line = 0
|
98
98
|
@log_requests = (options[:log_requests] == false ? false : true)
|
99
99
|
pretty! if options[:pretty]
|
@@ -107,22 +107,14 @@ module Elasticshell
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
-
def
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
Settings[name].dup.tap do |s|
|
115
|
-
cs.each_with_index do |c, index|
|
116
|
-
v = vs[index]
|
117
|
-
s.gsub!(c, v)
|
118
|
-
end
|
119
|
-
end
|
110
|
+
def prompt
|
111
|
+
verb_string = self.class.formatted_verb(verb)
|
112
|
+
scope_string = Elasticshell.format((scope.exists? ? :existing_scope_format : :missing_scope_format), "%s", scope.path)
|
113
|
+
Elasticshell.format((pretty? ? :pretty_prompt_format : :prompt_format), ["%s", "%v"], [scope_string, verb_string])
|
120
114
|
end
|
121
115
|
|
122
|
-
def
|
123
|
-
|
124
|
-
scope_string = format((scope.exists? ? :existing_scope_format : :missing_scope_format), "%s", scope.path)
|
125
|
-
format((pretty? ? :pretty_prompt_format : :prompt_format), ["%s", "%v"], [scope_string, verb_string])
|
116
|
+
def self.formatted_verb verb
|
117
|
+
Elasticshell.format((verb.to_s =~ /^(?:G|H)/i ? :passive_http_verb_format : :active_http_verb_format), "%v", verb.to_s.upcase)
|
126
118
|
end
|
127
119
|
|
128
120
|
def pretty?
|
@@ -164,7 +156,7 @@ EOF
|
|
164
156
|
end
|
165
157
|
|
166
158
|
def connect
|
167
|
-
eval_line("connect #{@initial_servers.join('
|
159
|
+
eval_line("connect #{@initial_servers.join(' ')}")
|
168
160
|
end
|
169
161
|
|
170
162
|
def loop
|
@@ -181,7 +173,7 @@ EOF
|
|
181
173
|
self.input = line.strip
|
182
174
|
command.evaluate!
|
183
175
|
rescue ::Elasticshell::Error => e
|
184
|
-
error
|
176
|
+
Elasticshell.error e.message
|
185
177
|
end
|
186
178
|
self.state = :read
|
187
179
|
self.line += 1
|
@@ -212,7 +204,7 @@ EOF
|
|
212
204
|
format_only_part_of(obj)
|
213
205
|
when obj.nil?
|
214
206
|
nil
|
215
|
-
when String
|
207
|
+
when obj.is_a?(String) || obj.is_a?(Fixnum)
|
216
208
|
obj
|
217
209
|
when pretty?
|
218
210
|
JSON.pretty_generate(obj)
|
data/lib/elasticshell/utils.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Elasticshell
|
4
|
+
|
5
|
+
class ElasticsearchConfigFile
|
6
|
+
|
7
|
+
attr_accessor :path
|
8
|
+
|
9
|
+
def initialize path
|
10
|
+
self.path = path
|
11
|
+
end
|
12
|
+
|
13
|
+
def readable?
|
14
|
+
File.exist?(path) && File.readable?(path)
|
15
|
+
end
|
16
|
+
|
17
|
+
def config
|
18
|
+
@config ||= YAML.load(File.new(path))
|
19
|
+
end
|
20
|
+
|
21
|
+
def hosts
|
22
|
+
return @hosts if @hosts
|
23
|
+
Elasticshell.debug("Looking for Elasticsearch hosts in #{path}...")
|
24
|
+
unicast_hosts = (config["discovery"]["zen"]["ping"]["unicast"]["hosts"] rescue nil)
|
25
|
+
unicast_hosts ||= (config["discovery"]["zen"]["ping"]["unicast.hosts"] rescue nil)
|
26
|
+
unicast_hosts ||= (config["discovery"]["zen"]["ping.unicast.hosts"] rescue nil)
|
27
|
+
unicast_hosts ||= (config["discovery"]["zen.ping.unicast.hosts"] rescue nil)
|
28
|
+
unicast_hosts ||= (config["discovery"]["zen.ping.unicast.hosts"] rescue nil)
|
29
|
+
unicast_hosts ||= (config["discovery.zen.ping.unicast.hosts"] rescue nil)
|
30
|
+
@hosts = case unicast_hosts
|
31
|
+
when String then unicast_hosts.split(',').map(&:strip)
|
32
|
+
when Array then unicast_hosts.map(&:to_s).map(&:strip)
|
33
|
+
else
|
34
|
+
[]
|
35
|
+
end.map do |unicast_host|
|
36
|
+
host(unicast_host)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def http_port
|
41
|
+
return @http_port if @http_port
|
42
|
+
port_string = (config["http"]["port"] rescue nil)
|
43
|
+
port_string ||= (config["http.port"] rescue nil)
|
44
|
+
@http_port = case port_string
|
45
|
+
when String, Fixnum then port_string.to_i
|
46
|
+
else 9200
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def host string
|
53
|
+
case string
|
54
|
+
when /^(.+)\[(.+)-(.+)\]$/ then [$1, $2].join(':')
|
55
|
+
when /^(.+):(.+)$/ then [$1, $2].join(':')
|
56
|
+
else
|
57
|
+
[string, http_port].map(&:to_s).join(':')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -1,9 +1,85 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
1
3
|
module Elasticshell
|
4
|
+
|
5
|
+
Settings.define(:log, :description => "Path to a log file (defaults to STDERR)", :env_var => "ES_LOG", :default => STDERR)
|
6
|
+
Settings.define(:log_level, :description => "Log level", :default => "info", :env_var => "ES_LOG_LEVEL")
|
7
|
+
|
8
|
+
Settings.define(:http_request_format,
|
9
|
+
:description => "Format string for an HTTP request. The string `%v' will be replaced by the (formatted) verb, `%h' by the host, `%p' by the path.",
|
10
|
+
:default => " \e[1m=> %v \e[0m\e[39m%h\e[1m%p\e[0m",
|
11
|
+
:internal => true)
|
12
|
+
|
13
|
+
Settings.define(:debug_format,
|
14
|
+
:description => "Format string for a a DEBUG log message. The string `%m' will be replaced by the message",
|
15
|
+
:default => "\e[1m\e[32mDEBUG:\e[0m %m",
|
16
|
+
:internal => true)
|
17
|
+
|
18
|
+
Settings.define(:info_format,
|
19
|
+
:description => "Format string for a a INFO log message. The string `%m' will be replaced by the message",
|
20
|
+
:default => "\e[1m\e[34mINFO:\e[0m %m",
|
21
|
+
:internal => true)
|
22
|
+
|
23
|
+
Settings.define(:warn_format,
|
24
|
+
:description => "Format string for a a WARN log message. The string `%m' will be replaced by the message",
|
25
|
+
:default => "\e[1m\e[35mWARN:\e[0m %m",
|
26
|
+
:internal => true)
|
27
|
+
|
28
|
+
Settings.define(:error_format,
|
29
|
+
:description => "Format string for a a ERROR log message. The string `%m' will be replaced by the message",
|
30
|
+
:default => "\e[1m\e[31mERROR:\e[0m %m",
|
31
|
+
:internal => true)
|
32
|
+
|
33
|
+
def self.log
|
34
|
+
@log ||= default_logger
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.default_logger
|
38
|
+
Logger.new(Settings[:log]).tap do |l|
|
39
|
+
begin
|
40
|
+
l.level = Logger::Severity.const_get(Settings[:log_level].to_s.upcase)
|
41
|
+
rescue NameError => e
|
42
|
+
STDERR.puts "WARN: Log severity must be one of #{Logger::Severity.map(&:to_s).join(', ')}. Setting severity to \"info\""
|
43
|
+
l.level = Logger::Severity::INFO
|
44
|
+
end
|
45
|
+
l.formatter = proc do |severity, datetime, progname, msg|
|
46
|
+
msg + "\n"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.format name, codes, values
|
52
|
+
cs = [codes].flatten
|
53
|
+
vs = [values].flatten
|
54
|
+
raise ArgumentError.new("Must provide the same number of format codes as value strings.") unless cs.length == vs.length
|
55
|
+
Settings[name].dup.tap do |s|
|
56
|
+
cs.each_with_index do |c, index|
|
57
|
+
v = vs[index]
|
58
|
+
s.gsub!(c, v)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
2
62
|
|
3
|
-
def self.
|
4
|
-
|
63
|
+
def self.request verb, host, path
|
64
|
+
log.info(format(:http_request_format, ["%v", "%h", "%p"], [Shell.formatted_verb(verb), host, path]))
|
5
65
|
end
|
6
66
|
|
7
|
-
|
67
|
+
def self.debug msg
|
68
|
+
log.debug(format(:debug_format, "%m", msg))
|
69
|
+
end
|
8
70
|
|
71
|
+
def self.info msg
|
72
|
+
log.info(format(:info_format, "%m", msg))
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.warn msg
|
76
|
+
log.warn(format(:warn_format, "%m", msg))
|
77
|
+
end
|
9
78
|
|
79
|
+
def self.error msg
|
80
|
+
log.error(format(:error_format, "%m", msg))
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
@@ -13,7 +13,7 @@ describe Commands::Connect do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should start a connection to the given comma-separated servers" do
|
16
|
-
@shell.client.should_receive(:connect).with(:servers => %w[http://123.123.123.123:9200 http://321.321.321.321:9200])
|
16
|
+
@shell.client.should_receive(:connect).with(:servers => %w[http://123.123.123.123:9200/ http://321.321.321.321:9200/])
|
17
17
|
expect(@shell.eval_line("connect http://123.123.123.123:9200 http://321.321.321.321:9200"))
|
18
18
|
end
|
19
19
|
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Commands::Request do
|
4
4
|
|
5
5
|
before do
|
6
|
-
@shell = Shell.new(:output => FakeOutput.new, :
|
6
|
+
@shell = Shell.new(:output => FakeOutput.new, :input => FakeOutput.new )
|
7
7
|
@shell.stub!(:connected?).and_return(true)
|
8
8
|
end
|
9
9
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticshell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- lib/elasticshell/scopes/index.rb
|
126
126
|
- lib/elasticshell/scopes/nodes.rb
|
127
127
|
- lib/elasticshell/commands/help.rb
|
128
|
+
- lib/elasticshell/commands/exit.rb
|
128
129
|
- lib/elasticshell/commands/connect.rb
|
129
130
|
- lib/elasticshell/commands/pretty.rb
|
130
131
|
- lib/elasticshell/commands/pwd.rb
|
@@ -137,11 +138,13 @@ files:
|
|
137
138
|
- lib/elasticshell/commands/blank.rb
|
138
139
|
- lib/elasticshell/commands/ls.rb
|
139
140
|
- lib/elasticshell/command.rb
|
141
|
+
- lib/elasticshell/runner.rb
|
140
142
|
- lib/elasticshell/shell.rb
|
141
143
|
- lib/elasticshell/client.rb
|
142
144
|
- lib/elasticshell/scopes.rb
|
143
145
|
- lib/elasticshell/utils/log.rb
|
144
146
|
- lib/elasticshell/utils/recognizes_verb.rb
|
147
|
+
- lib/elasticshell/utils/es_config.rb
|
145
148
|
- lib/elasticshell/utils/has_name.rb
|
146
149
|
- lib/elasticshell/utils/has_verb.rb
|
147
150
|
- lib/elasticshell/utils/error.rb
|
@@ -184,7 +187,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
184
187
|
version: '0'
|
185
188
|
segments:
|
186
189
|
- 0
|
187
|
-
hash:
|
190
|
+
hash: 4595416963629376856
|
188
191
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
192
|
none: false
|
190
193
|
requirements:
|