Skip to main content

Module cli

Module cli 

Source
Expand description

The command line: argument parsing, the shell hooks, booting the game shell and dispatch.

The player’s commands are described with clap (Cli, Command), with Czech help. The commands that the game shell’s own functions send are not: cd-hook and fd-hook are parsed by hand, before clap (parse_hook), because their arguments are arbitrary text. A cd target can be "", -, -P, -- or a directory literally named pre, and none of those may be taken for an option or a subcommand.

§Commands

shellgame [--shell bash|fish]            show the current level (outside the game shell: start it)
shellgame hint [-r|--repeat]             the next hint, or all revealed hints again
shellgame submit [ANSWER...]             answer the level ("-5" is an answer, words are joined)
shellgame status | skip | reset | exit | update
shellgame repeat [--section N] [--level ID]
shellgame show (--section | --level)
shellgame remove [--yes]
shellgame --version                      `shellgame <version> (<build>)`

Hidden: init (legacy), dev jump ID | next | prev | reload | start, --devmode, and the hook commands.

§The hook commands

cd-hook pre  <pwd> <prev> -- <cd args...>      may the player cd? exit 3 = no
cd-hook post <old pwd> <new pwd> -- <cd args...>
cd-hook [TARGET] [PWD]                         legacy: shells started by the Python version
cd-hook --post-move [PWD]                      legacy
fd-hook

A leading --devmode is accepted before any command, because the Python wrapper prefixed it.

§Exit status

0 for everything that is normal gameplay (a wrong answer included), 1 for errors and a declined remove, 2 for usage errors (also those of clap), 3 when a cd is blocked by the new hook. The legacy cd-hook blocks with 1, because the old wrapper treats any non-zero status as “blocked”.

Structs§

Cli
The command line of the player.

Enums§

Command
A command of the player.
DevCommand
A developer command (shellgame dev ...).
Hook
A command that the game shell’s functions send, parsed by hand.

Constants§

BUILD
The build that is reported by --version: $SHELLGAME_BUILD at compile time, or dev.

Functions§

command
The clap command of the player, with Czech help everywhere.
main
Runs the program and returns its exit status. The environment is read once, here.
parse
Parses the arguments (without the program name) of the player’s command line.
parse_hook
Recognizes the hook commands. Returns None for everything else, which then goes to clap.
run
Runs one command line (without the program name) in this environment and returns the exit status.
version_line
What shellgame --version prints: shellgame 0.2.0 (build-123).