Class: RSMP::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/rsmp/cli.rb

Instance Method Summary collapse

Instance Method Details

#convertObject


117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/rsmp/cli.rb', line 117

def convert
  unless options[:in]
    puts "Error: Input option missing"
    exit
  end

  unless options[:out]
    puts "Error: Output option missing"
    exit
  end

  unless File.exist? options[:in]
    puts "Error: Input path file #{options[:in]} not found"
    exit
  end

  sxl = RSMP::Convert::Import::YAML.read options[:in]
  RSMP::Convert::Export::JSONSchema.write sxl, options[:out]
end

#siteObject


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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rsmp/cli.rb', line 14

def site
  settings = {}
  log_settings = { 'active' => true }

  if options[:config]
    if File.exist? options[:config]
      settings = YAML.load_file options[:config]
      log_settings = settings.delete('log') || {}
    else
      puts "Error: Config #{options[:config]} not found"
      exit
    end
  end

  if options[:id]
    settings['site_id'] = options[:id]
  end

  if options[:supervisors]
    settings['supervisors'] = []
    options[:supervisors].split(',').each do |supervisor|
      ip, port = supervisor.split ':'
      ip = '127.0.0.1' if ip.empty?
      port = '12111' if port.empty?
      settings['supervisors'] << {"ip"=>ip, "port"=>port}
    end
  end

  if options[:log]
    log_settings['path'] = options[:log]
  end

  if options[:json]
    log_settings['json'] = options[:json]
  end

  site_class = RSMP::Site
  if options[:type]
    case options[:type]
      when 'tlc'
        site_class = RSMP::Tlc
      else
        site_class = RSMP::Site
    end
  end
  site_class.new(site_settings:settings, log_settings: log_settings).start
rescue RSMP::Schemer::UnknownSchemaTypeError => e
  puts "Cannot start site: #{e}"
rescue RSMP::Schemer::UnknownSchemaVersionError => e
  puts "Cannot start site: #{e}"
rescue Psych::SyntaxError => e
  puts "Cannot read config file #{e}"
end

#supervisorObject


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/rsmp/cli.rb', line 75

def supervisor
  settings = {}
  log_settings = { 'active' => true }

  if options[:config]
    if File.exist? options[:config]
      settings = YAML.load_file options[:config]
      log_settings = settings.delete 'log'
    else
      puts "Error: Config #{options[:config]} not found"
      exit
    end
  end

  if options[:id]
    settings['site_id'] = options[:id]
  end

  if options[:ip]
    settings['ip'] = options[:ip]
  end

  if options[:port]
    settings['port'] = options[:port]
  end

  if options[:log]
    log_settings['path'] = options[:log]
  end

  if options[:json]
    log_settings['json'] = options[:json]
  end

  RSMP::Supervisor.new(supervisor_settings:settings,log_settings:log_settings).start
rescue RSMP::ConfigurationError => e
  puts "Cannot start supervisor: #{e}"
end