Module: Lich::Main::ArgvOptions::OptionParser
- Defined in:
- documented/main/argv_options.rb
Overview
Parse ARGV and build @argv_options hash for backward compatibility
Class Method Summary collapse
-
.execute ⇒ Hash
private
Parses ARGV into a hash of option flags and values for backward compatibility.
-
.handle_dark_mode(value) ⇒ void
private
Sets dark mode flag based on --dark-mode argument value.
-
.handle_sal_file(arg) ⇒ void
private
Records a SAL or Gse.~xt launch file path in argv_options, resolving Windows paths and Wine prefix translations as needed.
-
.print_help(topic = nil) ⇒ void
private
Prints help text to stdout, optionally for a specific topic.
-
.print_version ⇒ void
private
Prints version information and copyright notices to stdout.
Class Method Details
.execute ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Modifies ARGV by calling handle_sal_file and may clear bad_args
Early-exit operations (help, version, SGE/SAL links, install) call exit and do not return
Parses ARGV into a hash of option flags and values for backward compatibility.
Processes command-line arguments including help, version, SGE/SAL linking, installation, game connection details, UI settings, and launch configuration. Exits immediately for early-exit operations (--help, --version, --install).
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 67 68 69 70 71 72 73 74 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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'documented/main/argv_options.rb', line 40 def self.execute @argv_options = {} bad_args = [] ARGV.each do |arg| case arg when '-h', '--help', /^--help=.+$/ print_help(HelpText.topic_from_argv(ARGV, arg)) exit when '-v', '--version' print_version exit when '--link-to-sge' result = Lich.link_to_sge $stdout.puts(result ? 'Successfully linked to SGE.' : 'Failed to link to SGE.') if $stdout.isatty exit when '--unlink-from-sge' result = Lich.unlink_from_sge $stdout.puts(result ? 'Successfully unlinked from SGE.' : 'Failed to unlink from SGE.') if $stdout.isatty exit when '--link-to-sal' result = Lich.link_to_sal $stdout.puts(result ? 'Successfully linked to SAL files.' : 'Failed to link to SAL files.') if $stdout.isatty exit when '--unlink-from-sal' result = Lich.unlink_from_sal $stdout.puts(result ? 'Successfully unlinked from SAL files.' : 'Failed to unlink from SAL files.') if $stdout.isatty exit when '--install' if Lich.link_to_sge && Lich.link_to_sal $stdout.puts 'Install was successful.' Lich.log 'Install was successful.' else $stdout.puts 'Install failed.' Lich.log 'Install failed.' end exit when '--uninstall' if Lich.unlink_from_sge && Lich.unlink_from_sal $stdout.puts 'Uninstall was successful.' Lich.log 'Uninstall was successful.' else $stdout.puts 'Uninstall failed.' Lich.log 'Uninstall failed.' end exit when /^--start-scripts=(.+)$/i @argv_options[:start_scripts] = $1 when /^--reconnect$/i @argv_options[:reconnect] = true when /^--reconnect-delay=(.+)$/i @argv_options[:reconnect_delay] = $1 when /^--host=(.+):(.+)$/ @argv_options[:host] = { domain: $1, port: $2.to_i } when /^--bind-address=(.+)$/i @argv_options[:bind_address] = $1 when /^--hosts-file=(.+)$/i @argv_options[:hosts_file] = $1 when /^--no-(?:gui|gtk)$/i @argv_options[:gui] = false when /^--gui$/i @argv_options[:gui] = true when /^--game=(.+)$/i @argv_options[:game] = $1 when /^--account=(.+)$/i @argv_options[:account] = $1 when /^--password=(.+)$/i @argv_options[:password] = $1 when /^--character=(.+)$/i @argv_options[:character] = $1 when /^--frontend=(.+)$/i @argv_options[:frontend] = $1 when /^--frontend-command=(.+)$/i @argv_options[:frontend_command] = $1 when /^--save$/i @argv_options[:save] = true when /^--pipe$/i @argv_options[:pipe] = true when /^--wine(?:\-prefix)?=.+$/i nil # already used when defining the Wine module when /\.sal$|Gse\.~xt$/i handle_sal_file(arg) bad_args.clear when /^--dark-mode=(true|false|on|off)$/i handle_dark_mode($1) when /^--saga$/i $frontend = 'saga' else bad_args.push(arg) end end @argv_options end |
.handle_dark_mode(value) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Sets dark mode flag based on --dark-mode argument value.
Converts string values like "true", "on", "false", "off" to a strict boolean.
162 163 164 165 |
# File 'documented/main/argv_options.rb', line 162 def self.handle_dark_mode(value) # Regex returns Integer/nil; force strict boolean for startup handling. @argv_options[:dark_mode] = !!(value =~ /^(true|on)$/i) end |
.handle_sal_file(arg) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Records a SAL or Gse.~xt launch file path in argv_options, resolving Windows paths and Wine prefix translations as needed.
Sets :sal key to the resolved file path. If the file does not exist, attempts to extract a Windows path from ARGV, then (if Wine is defined) translates the path to a Wine drive_c location.
145 146 147 148 149 150 151 152 153 |
# File 'documented/main/argv_options.rb', line 145 def self.handle_sal_file(arg) @argv_options[:sal] = arg unless File.exist?(@argv_options[:sal]) @argv_options[:sal] = $1 if ARGV.join(' ') =~ /([A-Z]:\\.+?\.(?:sal|~xt))/i end unless File.exist?(@argv_options[:sal]) @argv_options[:sal] = "#{Wine::PREFIX}/drive_c/#{@argv_options[:sal][3..-1].split('\\').join('/')}" if defined?(Wine) end end |
.print_help(topic = nil) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Prints help text to stdout, optionally for a specific topic.
172 173 174 |
# File 'documented/main/argv_options.rb', line 172 def self.print_help(topic = nil) puts HelpText.render(topic) end |
.print_version ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Prints version information and copyright notices to stdout.
180 181 182 183 184 185 186 187 188 189 190 |
# File 'documented/main/argv_options.rb', line 180 def self.print_version puts "The Lich, version #{LICH_VERSION}" puts ' (an implementation of the Ruby interpreter by Yukihiro Matsumoto designed to be a \'script engine\' for text-based MUDs)' puts '' puts '- The Lich program and all material collectively referred to as "The Lich project" is copyright (C) 2005-2006 Murray Miron.' puts '- The Gemstone IV and DragonRealms games are copyright (C) Simutronics Corporation.' puts '- The Wizard front-end and the StormFront front-end are also copyrighted by the Simutronics Corporation.' puts '- Ruby is (C) Yukihiro \'Matz\' Matsumoto.' puts '' puts 'Thanks to all those who\'ve reported bugs and helped me track down problems on both Windows and Linux.' end |