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

Defined in:
documented/main/argv_options.rb

Overview

Module for handling side effects of command line options This module applies side effects based on the parsed options.

Class Method Summary collapse

Class Method Details

.execute(argv_options) ⇒ Object



248
249
250
251
252
253
# File 'documented/main/argv_options.rb', line 248

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) ⇒ void

Note:

This method modifies the argv_options hash.

This method returns an undefined value.

Handles the detachable client option from command line arguments.

Parameters:

  • argv_options (Hash)

    The parsed command line options.



279
280
281
282
283
284
285
286
287
# File 'documented/main/argv_options.rb', line 279

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=((?:\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) ⇒ void

Note:

This method modifies the argv_options hash.

This method returns an undefined value.

Handles the hosts directory option from command line arguments.

Parameters:

  • argv_options (Hash)

    The parsed command line options.



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'documented/main/argv_options.rb', line 259

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) ⇒ void

Note:

This method may exit the program if the SAL file does not exist.

This method returns an undefined value.

Handles launching the SAL file if specified in options.

Parameters:

  • argv_options (Hash)

    The parsed command line options.



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'documented/main/argv_options.rb', line 293

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