Module: Lich::Main::ArgvOptions::OptionParser

Defined in:
documented/main/argv_options.rb

Overview

Module for parsing command line options This module defines methods to execute and handle command line options.

Examples:

Executing option parsing

options = Lich::Main::ArgvOptions::OptionParser.execute

Class Method Summary collapse

Class Method Details

.executeObject



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
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
# File 'documented/main/argv_options.rb', line 27

def self.execute
  @argv_options = {}
  bad_args = []

  ARGV.each do |arg|
    case arg
    when '-h', '--help'
      print_help
      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 /^--hosts-file=(.+)$/i
      @argv_options[:hosts_file] = $1
    when /^--no-gui$/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 /^--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)
    else
      bad_args.push(arg)
    end
  end

  @argv_options
end

.handle_dark_mode(value) ⇒ void

Note:

This method modifies the @argv_options hash.

This method returns an undefined value.

Handles the dark mode option from command line arguments.

Parameters:

  • value (String)

    The value indicating dark mode status (true|false|on|off).



134
135
136
137
138
139
140
# File 'documented/main/argv_options.rb', line 134

def self.handle_dark_mode(value)
  @argv_options[:dark_mode] = value =~ /^(true|on)$/i
  if defined?(Gtk)
    @theme_state = Lich.track_dark_mode = @argv_options[:dark_mode]
    Gtk::Settings.default.gtk_application_prefer_dark_theme = true if @theme_state == true
  end
end

.handle_sal_file(arg) ⇒ void

Note:

This method modifies the @argv_options hash.

This method returns an undefined value.

Handles the SAL file argument and validates its existence.

Parameters:

  • arg (String)

    The SAL file argument to handle.



120
121
122
123
124
125
126
127
128
# File 'documented/main/argv_options.rb', line 120

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

This method returns an undefined value.

Prints the help message for command line options.

Examples:

Displaying help

Lich::Main::ArgvOptions::OptionParser.print_help


146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'documented/main/argv_options.rb', line 146

def self.print_help
  puts 'Usage:  lich [OPTION]'
  puts 'General Options:'
  puts '  -h,   --help            Display this list.'
  puts '  -v,   --version         Display the program version number and credits.'
  puts '  -d,   --directory       Set the main Lich program directory.'
  puts '        --script-dir      Set the directory where Lich looks for scripts.'
  puts '        --data-dir        Set the directory where Lich will store script data.'
  puts '        --temp-dir        Set the directory where Lich will store temporary files.'
  puts '        --hosts-dir       Set the directory containing game server host definitions.'
  puts '        --hosts-file      Set the hosts file to use for host name resolution.'
  puts '  -w,   --wizard          Run in Wizard mode (default).'
  puts '  -s,   --stormfront      Run in StormFront mode.'
  puts '        --avalon          Run in Avalon mode.'
  puts '        --frostbite       Run in Frostbite mode.'
  puts '        --gui             Enable GUI (default).'
  puts '        --no-gui          Run without GUI (headless mode).'
  puts '        --dark-mode       Enable/disable dark mode (true|false|on|off). See example below.'
  puts '        --gemstone        Connect to the Gemstone IV Prime server (default).'
  puts '        --shattered       Connect to the Gemstone IV Shattered server.'
  puts '        --dragonrealms    Connect to the DragonRealms server.'
  puts '        --fallen          Connect to the DragonRealms Fallen server.'
  puts '        --platinum        Connect to the Gemstone IV/DragonRealms Platinum server.'
  puts '        --test            Connect to the test instance of the selected game server.'
  puts '  -g,   --game            Set the IP address and port of the game. See example below.'
  puts ''
  puts 'Login and Connection Options:'
  puts '        --login           Login with the specified character name.'
  puts '        --without-frontend Run without a frontend (headless mode).'
  puts '        --detachable-client Enable detachable client mode on specified port or host:port.'
  puts '        --reconnect       Automatically reconnect if connection is lost.'
  puts '        --reconnect-delay Set delay (in seconds) before attempting reconnection.'
  puts '        --start-scripts   Specify scripts to start after successful login.'
  puts '        --save            Save login credentials after successful login.'
  puts ''
  puts 'Account and Password Options:'
  puts '        --account         Specify game account name.'
  puts '        --password        Specify game account password.'
  puts '        --frontend        Specify frontend type (wizard, stormfront, avalon, genie, frostbite).'
  puts ''
  puts 'Encryption Management Options:'
  puts '  -aa, --add-account    Add a new account with password. See example below.'
  puts '  -cap, --change-account-password'
  puts '                        Change password for specified account. See example below.'
  puts '  -cmp, --change-master-password'
  puts '                        Change the master password for Enhanced encryption mode.'
  puts '  -rmp, --recover-master-password'
  puts '                        Recover a lost master password (requires backup recovery).'
  puts '        --convert-entries Convert existing account entries to specified encryption mode.'
  puts '                        Usage: --convert-entries [plaintext|standard|enhanced]'
  puts '  -cem, --change-encryption-mode'
  puts '                        Change the global encryption mode for all accounts.'
  puts '  -mp, --master-password'
  puts '                        Specify master password for Enhanced mode operations.'
  puts ''
  puts 'Legacy Installation Options:'
  puts '       --install         Configure Windows/WINE registry for SGE integration.'
  puts '       --uninstall       Remove Lich from registry.'
  puts '       --link-to-sge     Link Lich to Simutronics Game Entry.'
  puts '       --unlink-from-sge Unlink Lich from Simutronics Game Entry.'
  puts '       --link-to-sal     Link Lich to SAL (Simutronics Account Launcher).'
  puts '       --unlink-from-sal Unlink Lich from SAL.'
  puts ''
  puts 'Examples:'
  puts '  lich -w -d /usr/bin/lich/'
  puts '       ... (run Lich in Wizard mode using the dir \'/usr/bin/lich/\' as the program\'s home)'
  puts '  lich -g gs3.simutronics.net:4000'
  puts '       ... (run Lich using the IP address \'gs3.simutronics.net\' and the port number \'4000\')'
  puts '  lich --dragonrealms --test --genie'
  puts '       ... (run Lich connected to DragonRealms Test server for the Genie frontend)'
  puts '  lich --script-dir /mydir/scripts'
  puts '       ... (run Lich with its script directory set to \'/mydir/scripts\')'
  puts '  lich -aa MyAccount MyPassword --frontend stormfront'
  puts '       ... (add a new account with StormFront frontend)'
  puts '  lich -cap MyAccount NewPassword'
  puts '       ... (change password for MyAccount to NewPassword)'
  puts '  lich --convert-entries enhanced'
  puts '       ... (convert all saved entries to Enhanced encryption mode with master password)'
  puts '  lich --login MyCharName --no-gui --detachable-client=8000 --dark-mode=true'
  puts '       ... (login without GUI in headless mode with detachable client on port 8000)'
end

This method returns an undefined value.

Prints the version information of the Lich program.

Examples:

Displaying version

Lich::Main::ArgvOptions::OptionParser.print_version


232
233
234
235
236
237
238
239
240
241
242
# File 'documented/main/argv_options.rb', line 232

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