Module: Lich::Main::ArgvOptions::SideEffects

Defined in:
documented/main/argv_options.rb

Overview

Module for handling side effects of command-line options.

This module executes actions that result from the parsed command-line options.

Class Method Summary collapse

Class Method Details

.execute(argv_options) ⇒ Object



175
176
177
178
179
180
# File 'documented/main/argv_options.rb', line 175

def self.execute(argv_options)
  handle_hosts_dir(argv_options)
  handle_detachable_client(argv_options)
  handle_sal_launch(argv_options)
  argv_options
end

.handle_detachable_client(argv_options) ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
# File 'documented/main/argv_options.rb', line 198

def self.handle_detachable_client(argv_options)
  argv_options[:detachable_client_host] = '127.0.0.1'
  argv_options[:detachable_client_port] = nil
  if (arg = ARGV.find { |a| a =~ /^\-\-detachable\-client=[0-9]+$/ })
    argv_options[:detachable_client_port] = /^\-\-detachable\-client=([0-9]+)$/.match(arg).captures.first.to_i
  elsif (arg = ARGV.find { |a| a =~ /^\-\-detachable\-client=auto$/i })
    argv_options[:detachable_client_port] = 0
  elsif (arg = ARGV.find { |a| a =~ /^\-\-detachable\-client=((?:\d{1,3}\.){3}\d{1,3}):([0-9]{1,5})$/ })
    argv_options[:detachable_client_host], argv_options[:detachable_client_port] = /^\-\-detachable\-client=((?:\d{1,3}\.){3}\d{1,3}):([0-9]{1,5})$/.match(arg).captures
  end
end

.handle_hosts_dir(argv_options) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'documented/main/argv_options.rb', line 182

def self.handle_hosts_dir(argv_options)
  if (arg = ARGV.find { |a| a == '--hosts-dir' })
    i = ARGV.index(arg)
    ARGV.delete_at(i)
    hosts_dir = ARGV[i]
    ARGV.delete_at(i)
    if hosts_dir && File.exist?(hosts_dir)
      hosts_dir = hosts_dir.tr('\\', '/')
      hosts_dir += '/' unless hosts_dir[-1..-1] == '/'
      argv_options[:hosts_dir] = hosts_dir
    else
      $stdout.puts "warning: given hosts directory does not exist: #{hosts_dir}"
    end
  end
end

.handle_sal_launch(argv_options) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'documented/main/argv_options.rb', line 210

def self.handle_sal_launch(argv_options)
  return unless argv_options[:sal]

  unless File.exist?(argv_options[:sal])
    Lich.log "error: launch file does not exist: #{argv_options[:sal]}"
    Lich.msgbox "error: launch file does not exist: #{argv_options[:sal]}"
    exit
  end
  Lich.log "info: launch file: #{argv_options[:sal]}"

  if argv_options[:sal] =~ /SGE\.sal/i
    unless (launcher_cmd = Lich.get_simu_launcher)
      $stdout.puts 'error: failed to find the Simutronics launcher'
      Lich.log 'error: failed to find the Simutronics launcher'
      exit
    end
    launcher_cmd.sub!('%1', argv_options[:sal])
    Lich.log "info: launcher_cmd: #{launcher_cmd}"
    if defined?(Win32) && launcher_cmd =~ /^"(.*?)"\s*(.*)$/
      dir_file = $1
      param = $2
      dir = dir_file.slice(/^.*[\\\/]/)
      file = dir_file.sub(/^.*[\\\/]/, '')
      operation = (Win32.isXP? ? 'open' : 'runas')
      Win32.ShellExecute(lpOperation: operation, lpFile: file, lpDirectory: dir, lpParameters: param)
      Lich.log "error: Win32.ShellExecute returned #{r}; Win32.GetLastError: #{Win32.GetLastError}" if r < 33
    elsif defined?(Wine)
      system("#{Wine::BIN} #{launcher_cmd}")
    else
      system(launcher_cmd)
    end
    exit
  end
end