Class: MultiForecast::CLI
- Inherits:
-
Thor
- Object
- Thor
- MultiForecast::CLI
show all
- Includes:
- ConversionRule
- Defined in:
- lib/multiforecast/cli.rb
Instance Method Summary
collapse
#graph_name, #id, #ids, #lstrip, #path, #section_name, #service_name, #uri_escape, #uri_unescape
Constructor Details
#initialize(args = [], opts = [], config = {}) ⇒ CLI
Returns a new instance of CLI.
11
12
13
14
15
16
17
18
19
|
# File 'lib/multiforecast/cli.rb', line 11
def initialize(args = [], opts = [], config = {})
super(args, opts, config)
if options['config'] && File.exists?(options['config'])
@options = YAML.load_file(options['config']).merge(@options)
end
@client = MultiForecast::Client.new(@options)
end
|
Instance Method Details
#color ⇒ Object
75
76
77
78
79
|
# File 'lib/multiforecast/cli.rb', line 75
def color
base_path = lstrip(@options['base_path'], '/') if @options['base_path']
graphs = @client.list_graph(base_path)
setup_colors(@options['colors'], graphs)
end
|
#create_complex ⇒ Object
90
91
92
93
94
|
# File 'lib/multiforecast/cli.rb', line 90
def create_complex
base_path = lstrip(@options['base_path'], '/') if @options['base_path']
graphs = @client.list_graph(base_path)
setup_complex(options['from_graphs'], options['to_complex'], graphs)
end
|
#delete(base_path) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/multiforecast/cli.rb', line 55
def delete(base_path)
base_path = lstrip(base_path, '/')
regexp = Regexp.new(@options['regexp']) if @options['regexp']
graphs = @client.list_graph(base_path, regexp)
delete_graphs(graphs, @options['graph_names'])
complexes = @client.list_complex(base_path, regexp)
delete_complexes(complexes, @options['graph_names'])
$stderr.puts "Not found" if graphs.empty? and complexes.empty? unless @options['silent']
end
|
#generate(target) ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'lib/multiforecast/cli.rb', line 22
def generate(target)
config = {
'mapping' => { '' => 'http://localhost:5125' },
}
File.open("multiforecast.yml", "w") do |file|
YAML.dump(config, file)
$stdout.puts "Generated #{file.path}"
end
end
|
#post(json, path) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/multiforecast/cli.rb', line 38
def post(json, path)
path = lstrip(path, '/')
exec do
res = @client.post_graph(path, JSON.parse(json))
$stdout.puts res unless @options['silent']
end
end
|