exprc 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/exprc +46 -68
  2. data/exprc.gemspec +1 -1
  3. metadata +3 -2
data/bin/exprc CHANGED
@@ -23,7 +23,7 @@ ARGV.options do |o|
23
23
  divisor = nil
24
24
  percentile = nil
25
25
 
26
- o.banner = "usage: exprc list|show|test|create|destroy|version [options]"
26
+ o.banner = "usage: exprc list|show|explain|test|create|destroy|version [options]"
27
27
  o.on("-n", "--name n", String, "name of metric") { |n| name = n }
28
28
  o.on("-t", "--type t", String, "type of metric") { |t| type = t }
29
29
  o.on("-w", "--window w", Integer, "window of metric in seconds") { |w| window = w }
@@ -40,28 +40,34 @@ ARGV.options do |o|
40
40
  action = ARGV.shift
41
41
  exprd_api_url = ENV["EXPRD_API_URL"]
42
42
 
43
+ params = {
44
+ "type" => type,
45
+ "window" => window,
46
+ "delay" => delay,
47
+ "predicate" => (predicate && JSON.parse(predicate)),
48
+ "predicate2" => (predicate2 && JSON.parse(predicate2)),
49
+ "value" => value,
50
+ "key" => key,
51
+ "divisor" => divisor,
52
+ "percentile" => percentile,
53
+ "frequency" => frequency}
54
+
43
55
  abort("! error: an action is required (e.g list).\n\n#{o}") if (!action || action.empty?)
44
- abort("! error: unrecognized action #{action}.") if !%w{list show test create update destroy version}.include?(action)
56
+ abort("! error: unrecognized action #{action}.") if !%w{list show explain test create update destroy version}.include?(action)
45
57
  abort("! error: missing EXPRD_API_URL.\n\n#{o}") if (!exprd_api_url || exprd_api_url.empty?)
46
58
  abort("! error: unrecognized args: #{ARGV.join(" ")}.") if !ARGV.empty?
47
59
 
48
- case action
49
- when "version"
50
- puts("0.0.5")
51
- when "list"
52
- begin
60
+ begin
61
+ case action
62
+ when "version"
63
+ puts("0.0.6")
64
+ when "list"
53
65
  names = JSON.parse(RestClient.get("#{exprd_api_url}/metrics"))
54
66
  names.each do |name|
55
67
  puts("- #{name}")
56
68
  end
57
- rescue => e
58
- puts(" failed")
59
- message = e.is_a?(RestClient::Exception) ? JSON.parse(e.response.body)["message"] : e.message
60
- abort("! error: #{message}")
61
- end
62
- when "show"
63
- abort("! error: missing --name.\n\n#{o}") if (!name || name.empty?)
64
- begin
69
+ when "show"
70
+ abort("! error: missing --name.\n\n#{o}") if (!name || name.empty?)
65
71
  info = JSON.parse(RestClient.get("#{exprd_api_url}/metrics/#{name}"))
66
72
  puts("= name: #{name}")
67
73
  puts("= type: #{info["type"]}")
@@ -74,68 +80,40 @@ ARGV.options do |o|
74
80
  puts("= divisor: #{info["divisor"]}") if info["divisor"]
75
81
  puts("= percentile: #{info["percentile"]}") if info["percentile"]
76
82
  puts("= frequency: #{info["frequency"]}")
77
- rescue => e
78
- puts(" failed")
79
- message = e.is_a?(RestClient::Exception) ? JSON.parse(e.response.body)["message"] : e.message
80
- abort("! error: #{message}")
81
- end
82
- when "test"
83
- abort("! error: missing --name.\n\n#{o}") if (!name || name.empty?)
84
- $stdout.print("* testing metric #{name}...")
85
- begin
86
- params = {
87
- "type" => type,
88
- "window" => window,
89
- "delay" => delay,
90
- "predicate" => (predicate && JSON.parse(predicate)),
91
- "predicate2" => (predicate2 && JSON.parse(predicate2)),
92
- "value" => value,
93
- "key" => key,
94
- "divisor" => divisor,
95
- "percentile" => percentile,
96
- "frequency" => frequency}
83
+ when "explain"
84
+ abort("! error: missing --name.\n\n#{o}") if (!name || name.empty?)
85
+
86
+ if type
87
+ #we are sending the params
88
+ info = JSON.parse(RestClient.put("#{exprd_api_url}/metrics/#{name}/tests", JSON.dump(params)))
89
+ else
90
+ #we are getting a known metric
91
+ info = JSON.parse(RestClient.get("#{exprd_api_url}/metrics/#{name}"))
92
+ end
93
+ puts("= name: #{name}")
94
+ puts("= compiled:\n#{info["compiled"]}")
95
+ when "test"
96
+ abort("! error: missing --name.\n\n#{o}") if (!name || name.empty?)
97
+ $stdout.print("* testing metric #{name}...")
97
98
  results = JSON.parse(RestClient.put("#{exprd_api_url}/metrics/#{name}/tests", JSON.dump(params)))
98
99
  puts(" done")
99
100
  puts("= name: #{name}")
100
101
  puts("= value: #{results["value"]}")
101
102
  puts("= time: #{Time.at(results["time"])}")
102
- rescue => e
103
- puts(" failed")
104
- message = e.is_a?(RestClient::Exception) ? JSON.parse(e.response.body)["message"] : e.message
105
- abort("! error: #{message}")
106
- end
107
- when "create"
108
- abort("! error: missing --name.\n\n#{o}") if (!name || name.empty?)
109
- $stdout.print("* creating metric #{name}...")
110
- begin
111
- params = {
112
- "type" => type,
113
- "window" => window,
114
- "delay" => delay,
115
- "predicate" => (predicate && JSON.parse(predicate)),
116
- "predicate2" => (predicate2 && JSON.parse(predicate2)),
117
- "value" => value,
118
- "key" => key,
119
- "divisor" => divisor,
120
- "percentile" => percentile,
121
- "frequency" => frequency}
103
+ when "create"
104
+ abort("! error: missing --name.\n\n#{o}") if (!name || name.empty?)
105
+ $stdout.print("* creating metric #{name}...")
122
106
  RestClient.put("#{exprd_api_url}/metrics/#{name}", JSON.dump(params))
123
107
  puts(" done")
124
- rescue => e
125
- puts(" failed")
126
- message = e.is_a?(RestClient::Exception) ? JSON.parse(e.response.body)["message"] : e.message
127
- abort("! error: #{message}")
128
- end
129
- when "destroy"
130
- abort("! error: missing --name.\n\n#{o}") if (!name || name.empty?)
131
- $stdout.print("* destroying metric #{name}...")
132
- begin
108
+ when "destroy"
109
+ abort("! error: missing --name.\n\n#{o}") if (!name || name.empty?)
110
+ $stdout.print("* destroying metric #{name}...")
133
111
  RestClient.delete("#{exprd_api_url}/metrics/#{name}")
134
112
  puts(" done")
135
- rescue => e
136
- puts(" failed")
137
- message = e.is_a?(RestClient::Exception) ? JSON.parse(e.response.body)["message"] : e.message
138
- abort("! error: #{message}")
139
113
  end
114
+ rescue => e
115
+ puts(" failed")
116
+ message = e.is_a?(RestClient::Exception) ? JSON.parse(e.response.body)["message"] : e.message
117
+ abort("! error: #{message}")
140
118
  end
141
119
  end
@@ -9,5 +9,5 @@ Gem::Specification.new do |gem|
9
9
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
10
10
  gem.name = "exprc"
11
11
  gem.require_paths = ["lib"]
12
- gem.version = "0.0.5"
12
+ gem.version = "0.0.6"
13
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exprc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
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-04-08 00:00:00.000000000 Z
12
+ date: 2012-05-22 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: CLI to exprd.
15
15
  email:
@@ -50,3 +50,4 @@ signing_key:
50
50
  specification_version: 3
51
51
  summary: CLI to exprd.
52
52
  test_files: []
53
+ has_rdoc: