Class: GrafanaReporter::ConsoleConfigurationWizard

Inherits:
Object
  • Object
show all
Defined in:
lib/grafana_reporter/console_configuration_wizard.rb

Overview

This class provides a console configuration wizard, to reduce the manual efforts that have to be spent for that action and to reduce mistakes as good as possible.

Instance Method Summary collapse

Instance Method Details

#start_wizard(config_file, console_config) ⇒ Object

Provides a command line configuration wizard for setting up the necessary configuration file.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/grafana_reporter/console_configuration_wizard.rb', line 9

def start_wizard(config_file, console_config)
  action = overwrite_or_use_config_file(config_file)
  return if action == 'abort'

  config = create_config_wizard(config_file, console_config) if action == 'overwrite'
  config ||= Configuration.new

  begin
    config.config = YAML.load_file(config_file)
  rescue StandardError => e
    raise ConfigurationError, "Could not read config file '#{config_file}' (Error: #{e.message})\n"\
          "Source:\n#{File.read(config_file)}"
  end

  begin
    config.validate(true)
    puts 'Configuration file validated successfully.'
  rescue ConfigurationError => e
    raise e
  end

  demo_report = create_demo_report(config)

  demo_report ||= '<<your_report_name>>'
  config_param = config_file == Configuration::DEFAULT_CONFIG_FILE_NAME ? '' : " -c #{config_file}"
  program_call = "#{Gem.ruby} #{$PROGRAM_NAME}"
  program_call = ENV['OCRAN_EXECUTABLE'].gsub("#{Dir.pwd}/".gsub('/', '\\'), '') if ENV['OCRAN_EXECUTABLE']

  puts
  puts 'Now everything is setup properly. Create your reports as required in the templates '\
       'folder and run the reporter either standalone with e.g. the following command:'
  puts
  puts "   #{program_call}#{config_param} -t #{demo_report} -o demo_report.#{config.report_class.default_result_extension}"
  puts
  puts 'or run it as a service using the following command:'
  puts
  puts "   #{program_call}#{config_param}"
  puts
  puts "Open 'http://localhost:#{config.webserver_port}/render?var-template=#{demo_report}' in a webbrowser to"\
       ' test your configuration.'
end