The tools command finds and runs two kinds of tool:
record shows one record’s fields across several saves. holders shows who holds what across saves. These are what tools list shows.tests/one-offs: small checks and fixes written while working on a save. There are a couple of hundred of them, so tools list shows them only when you ask, with --dev or the environment variable CK3UPDATE_TOOLS_ALL=1.tools run runs a tool of either kind by name, and tools path prints where one is. Nothing extra needs installing.
The command never changes a tool, and writes nothing anywhere. Each tool runs exactly as it would if you ran it yourself: as its own process, from your current folder, with your terminal’s input and output and the arguments you give. tools run exits with the tool’s own exit code. A toolbox tool runs as python -m ck3_save_migrator.toolbox.<name>. A script runs as a file, python <script>, never as a module, whatever else its folder holds.
ck3update tools list
ck3update tools list --dev
ck3update tools run record --county c_vianden "Old.ck3" "New.ck3"
ck3update tools run diff_saves "Old.ck3" "New.ck3"
ck3update tools path diff_saves
tools list prints one line per toolbox tool: its name and what it does. When a scripts folder is found, one more line (on stderr) says how many scripts were not listed.tools list --dev lists the toolbox and then every script, under their own headings. Setting CK3UPDATE_TOOLS_ALL=1 does the same for every tools list. A script’s description is the first line of its docstring (empty when it has none). Nothing is run or imported to list it; the docstring is read from the file.tools run <name> [args...] runs the tool <name> with every argument after the name passed on unchanged, options included. You do not need --dev to run a script. When the toolbox and the scripts folder both have a tool by that name, the toolbox’s runs, and tools list --dev marks the script.tools run <name> --help shows the tool’s own help when the tool has one. A script that parses its arguments (it uses argparse or a similar library) gets --help like any other argument and answers it itself.--help. Passing it on could make such a script do its work with --help as an input. For those, tools run <name> --help (or -h) prints the script’s docstring and where the script is, and runs nothing.tools path <name> prints the script’s full path, for opening it or running it yourself.Every *.py file directly in the scripts folder is a script tool, named by its file name without .py. Other files and subfolders are not tools. Every module in the package’s toolbox that defines main is a toolbox tool; its helper modules are not. An unknown name is refused, naming it, with exit code 2.
Some scripts start the game, send input to its window, pause a running game’s threads to read them, or write files in the game’s folder under Documents. tools list marks each of them with [acts on the game: run needs --acts-on-game], and tools run refuses one unless you ask for it:
ck3update tools run --acts-on-game launch_load_test my-run -debug_mode
The flag goes after run and before the script’s name. Without it the command says why it stopped and exits with code 2. Nothing is started. Without the flag, --help on such a script prints its docstring and never starts it, whether or not it has a help of its own.
A script is marked by one comment line in its own source, so the mark stays with the script wherever it is copied:
# ck3update-tools: acts-on-game
Add that line to a script of your own that acts on the game. A script without the line runs as before.
The first of these that is set:
--scripts-dir <folder>, written after tools and before list, run or path: ck3update tools --scripts-dir my_scripts list;CK3SM_SCRIPTS_DIR;tests/one-offs folder of the source checkout the tool is running from. An installed package has no such folder.The toolbox needs no scripts folder, so tools list, and tools run of a toolbox tool, work in an installed package. When no scripts folder is found, tools list --dev and a script name given to tools run or tools path say so and exit with code 2.
A run patch can name a script from the scripts folder instead of spelling out its command:
[run]
tool = "edit_save"
args = ["@@input@@", "@@output@@"]
This runs <scripts folder>/edit_save.py with the Python running the tool, followed by args, which take the same @@name@@ variables as command: the same command tools run builds. It is the same as command = ["@@python@@", "<scripts folder>/edit_save.py", "@@input@@", "@@output@@"]. The scripts folder is the variable scripts_dir when given (--var scripts_dir=<folder>), else found as above; when there is none, or the script is not in it, the patch is refused, naming the folder. Like any run patch in a pack folder, it needs --allow-run, or a trusted pack in your packs folder.
A script marked as acting on the game (the # ck3update-tools: acts-on-game line above) gets the same gate here as in tools run. The patch must say so in its [run] table:
[run]
tool = "launch_load_test"
args = ["@@input@@"]
acts_on_game = true
Without acts_on_game = true, a patch naming such a script is refused before anything is written or started, naming the script. A patch naming an unmarked script needs no such line. acts_on_game goes with tool only.