Class: Norikra::Client::Query
- Inherits:
-
Thor
- Object
- Thor
- Norikra::Client::Query
show all
- Includes:
- CLIUtil
- Defined in:
- lib/norikra/client/cli.rb
Instance Method Summary
collapse
Methods included from CLIUtil
#client, #formatter, #parser, #wrap
Instance Method Details
#add(query_name, expression) ⇒ Object
98
99
100
101
102
|
# File 'lib/norikra/client/cli.rb', line 98
def add(query_name, expression)
wrap do
client(parent_options).register(query_name, options[:group], expression)
end
end
|
#dump ⇒ Object
126
127
128
129
130
131
132
133
134
|
# File 'lib/norikra/client/cli.rb', line 126
def dump
require 'json'
wrap do
queries = client(parent_options).queries
puts JSON.pretty_generate(queries)
end
end
|
#list ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/norikra/client/cli.rb', line 79
def list
wrap do
puts ["NAME", "GROUP", "TARGETS", "SUSPENDED", "QUERY"].join("\t") unless options[:simple]
queries = client(parent_options).queries
queries.sort{|a,b| (a['targets'].first <=> b['targets'].first).nonzero? || a['name'] <=> b['name']}.each do |q|
puts [
q['name'],
(q['group'] || 'default'),
q['targets'].join(','),
q['suspended'].to_s,
q['expression'].split("\n").map(&:strip).join(" ")
].join("\t")
end
puts "#{queries.size} queries found." unless options[:simple]
end
end
|
#remove(query_name) ⇒ Object
105
106
107
108
109
|
# File 'lib/norikra/client/cli.rb', line 105
def remove(query_name)
wrap do
client(parent_options).deregister(query_name)
end
end
|
#resume(query_name) ⇒ Object
119
120
121
122
123
|
# File 'lib/norikra/client/cli.rb', line 119
def resume(query_name)
wrap do
client(parent_options).resume(query_name)
end
end
|
#suspend(query_name) ⇒ Object
112
113
114
115
116
|
# File 'lib/norikra/client/cli.rb', line 112
def suspend(query_name)
wrap do
client(parent_options).suspend(query_name)
end
end
|
#sync ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/norikra/client/cli.rb', line 138
def sync
require 'json'
wrap do
load_queries = JSON.load($stdin)
server_queries = client(parent_options).queries
prefix = options[:dry_run] ? "[dry-run] " : ""
(server_queries - load_queries).each do |q|
puts "#{prefix}remove query #{q}"
unless options[:dry_run]
client(parent_options).deregister(q['name'])
end
end
(load_queries - server_queries).each do |q|
puts "#{prefix}add query #{q}"
unless options[:dry_run]
client(parent_options).register(q['name'], q['group'], q['expression'])
end
end
end
end
|