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, handling system integration (SGE/SAL linking), game connection modes, authentication, and frontend selection.
-
.handle_dark_mode(value) ⇒ void
private
Converts the --dark-mode argument value to a strict boolean and stores it.
-
.handle_sal_file(arg) ⇒ void
private
Resolves a .sal or .~xt launch file path and stores it in @argv_options.
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.
Does not apply side effects; use SideEffects.execute afterward
Parses ARGV into a hash of option flags and values, handling system integration (SGE/SAL linking), game connection modes, authentication, and frontend selection.
Recognizes long-form options (--start-scripts, --host, --game, etc.) and performs early exit for installation/system linking operations. Normalizes host:port pairs, resolves .sal/.~xt launch files, and applies dark mode settings.
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 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 |
# File 'documented/main/argv_options.rb', line 38 def self.execute @argv_options = {} bad_args = [] ARGV.each do |arg| case arg 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 /^--auth-provider=(eaccess|web)$/i @argv_options[:auth_provider] = $1.downcase.to_sym 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.
Converts the --dark-mode argument value to a strict boolean and stores it.
Accepts "true", "on" (case-insensitive) as truthy; all other values are falsy. Ensures the stored value is a pure [Boolean], not a Regexp match result.
157 158 159 160 |
# File 'documented/main/argv_options.rb', line 157 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.
Resolves a .sal or .~xt launch file path and stores it in @argv_options.
Attempts three resolution strategies: use the argument as-is, extract a Windows path from ARGV (e.g., C:\folder\file.sal), and translate it to a Wine prefix path if Wine is defined. Logs the final resolved path but does not validate existence—that is deferred to SideEffects.handle_sal_launch.
139 140 141 142 143 144 145 146 147 |
# File 'documented/main/argv_options.rb', line 139 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 |