Module: Lich::Main::HelpText

Defined in:
documented/main/help_text.rb

Overview

Renders user-facing CLI help text by topic.

Constant Summary collapse

HELP_TOPICS =

Valid help topic names available to render.

%w[login accounts automation paths advanced].freeze

Class Method Summary collapse

Class Method Details

.accounts_help ⇒ String

Returns formatted help text for the accounts topic.

Covers account management commands, encryption modes, game codes, and examples.

Examples:

Lich::Main::HelpText.render("accounts") #=> "Lich Help: accounts\n..."

Returns:

  • (String) —

    formatted help text for accounts



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

def self.accounts_help
  <<~TEXT
    Lich Help: accounts

    Usage:
      lich [account command] [options]

    Commands:
      --add-account ACCOUNT PASSWORD [--frontend FRONTEND]
      --refresh-characters ACCOUNT [--frontend FRONTEND]
      --add-character ACCOUNT CHAR_NAME --game-code CODE [--frontend FRONTEND]
      --change-account-password ACCOUNT NEWPASSWORD
      --change-master-password OLDPASSWORD [NEWPASSWORD]
      --recover-master-password [NEWPASSWORD]
      --convert-entries MODE
      --change-encryption-mode MODE [--master-password PASSWORD]

    Modes:
      plaintext
      standard
      enhanced

    Game codes (--game-code):
      GS3  GemStone IV              DR   DragonRealms
      GST  GemStone IV Prime Test   DRX  DragonRealms Platinum
      GSF  GemStone IV Shattered    DRT  DragonRealms Prime Test
                                    DRF  DragonRealms Fallen

    Examples:
      lich --add-account MYACCOUNT MYPASSWORD --frontend stormfront
      lich --refresh-characters MYACCOUNT
      lich --add-character MYACCOUNT NewCharName --game-code DR
      lich --change-account-password MYACCOUNT NEWPASSWORD
      lich --convert-entries enhanced
      lich --change-encryption-mode enhanced --master-password SECRET
  TEXT
end

.advanced_help ⇒ String

Returns formatted help text for the advanced topic.

Covers compatibility options, GUI behavior, frontend handshake manipulation, address binding, and detachable clients.

Examples:

Lich::Main::HelpText.render("advanced") #=> "Lich Help: advanced\n..."

Returns:

  • (String) —

    formatted help text for advanced



280
281
282
283
284
285
286
287
288
289
290
291
292
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
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'documented/main/help_text.rb', line 280

def self.advanced_help
  <<~TEXT
    Lich Help: advanced

    Compatibility / advanced options:
      --gui
      --no-gui, --no-gtk  Run without the GTK GUI (aliases)
      --without-frontend
      --detachable-client=PORT|auto|HOST:PORT
      --pipe
      --sentinel
      --frontend-caps=LIST
      --frontend=NAME
      --frontend-command=CMD
      --fe-version=VALUE
      --keep-fe-string
      --game=HOST:PORT
      --bind-address=HOST

    Notes:
      The GTK GUI starts by default. To suppress it, pass --no-gui or --no-gtk,
      including when using --headless.
      Prefer --headless PORT or --headless auto for new headless launches.
      --fe-version=VALUE reports the frontend version (e.g. 1.0.1.28) in the
      /VERSION: field of the game handshake Lich builds: --without-frontend, and
      the handshake that replaces a proxied frontend's own (below). Wizard, Avalon
      and Frostbite always send the default. VALUE: 1-32 of A-Z a-z 0-9 . _ + -
      DragonRealms currently needs the default /VERSION:1.0.1.28 for its full XML
      stream; another value may lose it.
      A frontend that connects through Lich and sends its own /FE: ... /XML
      handshake (Genie, Warlock, Wrayth, Frostbite without --frostbite) has it
      replaced with Lich's, so every session gets the same game stream; Lich
      reshapes that stream for the frontend. Saga's own /P:SAGA handshake is
      replaced too.
      --keep-fe-string forwards the frontend's own handshake instead, for that
      launch. To keep it for every launch: ;e Lich.keep_fe_string = true
      (;e Lich.keep_fe_string = false undoes it).
      --pipe uses stdin/stdout as the client transport instead of a front-end socket.
      With -g HOST:PORT, name the client reading it with a frontend flag (--frontend=NAME, --stormfront);
      without one the frontend is unknown and script output is not XML-escaped.
      --sentinel prefixes each line forwarded from the game with the origin marker
      (0x1F) for a client that strips it, whichever frontend it identifies as.
      --frontend-caps=LIST names the DragonRealms rich-stream features every attached
      client renders itself (room_element, game_links, double_bold; comma-separated),
      in place of the frontend's defaults. Lich rewrites the rest to the legacy
      stream. A client's own SET_FRONTEND_CAPS line takes precedence.
      --bind-address=HOST sets the local address Lich binds its listen sockets to
      (the frontend, --game proxy, and detachable-client listeners).
      Defaults to 127.0.0.1.
      HOST -- in --bind-address, --headless, and --detachable-client alike -- may
      be an IP, a hostname, a keyword, or (with a port) a bracketed IPv6 literal
      such as [::1]:PORT. Keywords: tailscale (this machine's Tailscale address),
      lan (its private LAN address), or any (0.0.0.0). Lich's listen sockets are
      unauthenticated - anyone who can reach one controls the session - so
      prefer tailscale over lan or any.
      Multiple frontends may attach to one detachable port. Each receives game
      output, and commands from all attached frontends are processed serially.
      Compatibility flags remain supported but are intentionally omitted from the default help screen.
  TEXT
end

.automation_help ⇒ String

Returns formatted help text for the automation topic.

Covers live session discovery and coordination through shared directories.

Examples:

Lich::Main::HelpText.render("automation") #=> "Lich Help: automation\n..."

Returns:

  • (String) —

    formatted help text for automation



208
209
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
# File 'documented/main/help_text.rb', line 208

def self.automation_help
  <<~TEXT
    Lich Help: automation

    Usage:
      lich [automation command]

    Commands:
      --active-sessions       List live sessions
      --session-info NAME     Show live session details for NAME

    Examples:
      lich --active-sessions
      lich --session-info Mychar

    Notes:
      Active session discovery coordinates through TEMP_DIR by default. If
      each character uses a separate --temp-dir, pass a shared
      --active-session-dir=PATH so all characters coordinate through one
      directory instead of isolated per-character ones.

      Passing --active-session-dir=PATH also enables the active sessions
      service for that launch, even if it isn't persistently enabled.
      This is a per-launch opt-in only -- it persists no setting, so
      omitting the flag on a later launch reverts to the persisted
      setting (disabled by default). The service itself still writes
      coordination files (a lock and a discovery record) into the
      directory while it runs.
  TEXT
end

.default_help ⇒ String

Returns the default help text shown when no topic is specified.

Examples:

Lich::Main::HelpText.render #=> "Lich 5\nUsage:\n  lich [command] [options]\n..."

Returns:

  • (String) —

    formatted help text listing common commands and available topics



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'documented/main/help_text.rb', line 72

def self.default_help
  <<~TEXT
    Lich 5
    Usage:
      lich [command] [options]

    Most common:
      lich --login CHARACTER
      lich --login CHARACTER --headless PORT
      lich --login CHARACTER --headless auto
      lich --add-account ACCOUNT PASSWORD

    Help topics:
      lich --help login
      lich --help accounts
      lich --help automation
      lich --help paths
      lich --help advanced

    General:
      --help                  Show help
      --version               Show version
  TEXT
end

.login_help ⇒ String

Returns formatted help text for the login topic.

Covers login options, game selection, frontend selection, advanced launch options, and examples.

Examples:

Lich::Main::HelpText.render("login") #=> "Lich Help: login\n..."

Returns:

  • (String) —

    formatted help text for login



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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'documented/main/help_text.rb', line 104

def self.
  <<~TEXT
    Lich Help: login

    Usage:
      lich --login CHARACTER [options]

    Login options:
      --login CHARACTER       Login using a saved entry
      --headless PORT         Run without a frontend and expose a detachable client on PORT
      --headless auto         Run without a frontend and let the OS assign a detachable port
      --headless HOST:PORT    Bind the detachable client to HOST (tailscale, lan, any, IP, or hostname)
      --start-scripts=LIST    Start scripts after login (comma-separated)
      --save                  Save successful CLI login details to entry.yaml
      --reconnect             Reconnect automatically if the session drops
      --reconnect-delay=SPEC  Delay before reconnecting

    Game selection:
      --gemstone, --gs
      --dragonrealms, --dr
      --shattered
      --fallen
      --platinum
      --test

    Frontend selection:
      --wizard
      --stormfront
      --avalon
      --frostbite
      --genie
      --saga
        Native saved Saga entries use Saga-managed Via Lich login and
        require the matching account credentials to be saved in Saga.

    Advanced launch:
      --custom-launch=NAME
      --detachable-client=PORT|auto|HOST:PORT
      --dark-mode=true|false
      --game=HOST:PORT

    Examples:
      lich --login Mychar
      lich --login Mychar --gemstone --shattered
      lich --login Mychar --frostbite
      lich --login Mychar --headless 8001
      lich --login Mychar --headless auto
      lich --login Mychar --headless tailscale:8001
      lich --login Mychar --start-scripts=repository,go2
  TEXT
end

.normalize_topic(topic) ⇒ String?

Normalizes user-facing aliases for help topic names.

Parameters:

Returns:



54
55
56
57
58
59
60
61
62
63
64
65
# File 'documented/main/help_text.rb', line 54

def self.normalize_topic(topic)
  case topic.to_s.downcase
  when '', 'overview' then nil
  when 'account', 'accounts' then 'accounts'
  when 'automation', 'automations', 'sessions', 'diagnostics' then 'automation'
  when 'login' then 'login'
  when 'path', 'paths' then 'paths'
  when 'advanced', 'compat', 'compatibility' then 'advanced'
  else
    nil
  end
end

.paths_help ⇒ String

Returns formatted help text for the paths topic.

Covers command-line options for customizing Lich's directory layout.

Examples:

Lich::Main::HelpText.render("paths") #=> "Lich Help: paths\n..."

Returns:

  • (String) —

    formatted help text for paths



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'documented/main/help_text.rb', line 246

def self.paths_help
  <<~TEXT
    Lich Help: paths

    Usage:
      lich [options]

    Path options:
      --home=PATH
      --script-dir=PATH
      --data-dir=PATH
      --temp-dir=PATH
      --map-dir=PATH
      --log-dir=PATH
      --backup-dir=PATH
      --lib-dir=PATH
      --hosts-dir=PATH
      --hosts-file=PATH
      --active-session-dir=PATH

    Examples:
      lich --script-dir=/my/scripts
      lich --data-dir=/my/data --temp-dir=/tmp/lich
      lich --temp-dir=/tmp/lich-Mychar --active-session-dir=/tmp/lich-sessions
  TEXT
end

.render(topic = nil) ⇒ String

Returns formatted help text for the requested topic.

Parameters:

  • topic (String, nil) (defaults to: nil) —

    optional topic name

Returns:

  • (String) —

    rendered help output



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'documented/main/help_text.rb', line 19

def self.render(topic = nil)
  normalized_topic = normalize_topic(topic)

  case normalized_topic
  when 'login' then 
  when 'accounts' then accounts_help
  when 'automation' then automation_help
  when 'paths' then paths_help
  when 'advanced' then advanced_help
  else
    default_help
  end
end

.topic_from_argv(argv, help_arg) ⇒ String?

Resolves the topic token following --help, if any.

Parameters:

  • argv (Array<String>) —

    command line arguments

  • help_arg (String) —

    the matched help flag

Returns:

  • (String, nil) —

    requested topic name



38
39
40
41
42
43
44
45
46
47
48
# File 'documented/main/help_text.rb', line 38

def self.topic_from_argv(argv, help_arg)
  return help_arg.split('=', 2).last if help_arg.start_with?('--help=')

  help_index = argv.index(help_arg)
  return nil if help_index.nil?

  topic = argv[help_index + 1]
  return nil if topic.nil? || topic.start_with?('--')

  topic
end