How do I create shell commands for a new entity?
Table of Contents
The unit shape, the two shapes and the file locations are in Shell entity patterns. The compass-codegen-add-surface-entity skill drives this process.
1. Question
How do I add shell REPL commands for a new entity in ores.shell?
2. Answer
Do not write the unit. Generate it.
- Annotate the columns. The add verb reads one positional per
user-supplied column. The
:supplied_by:annotation on a column names its source, and it has four values:user,minted,session_partyandunset. Most columns need no annotation, becauseuseris the default, and a uuid primary key already defaults tominted. Write the annotation only where the default is wrong. A column the caller does not supply takesunset; a column that holds the acting party takessession_party. Opt the entity in. Add this entry to the top-level properties drawer of the entity model, beside
:ID:::ores.cpp.shell-command.enabled: trueGenerate the unit.
./compass.sh codegen generate --model projects/ores.<component>/modeling/ores.<component>.<entity>.org --address ores.cpp.shell-command
Three files appear in the entity's adapter part: a header, an implementation and a test. The archetype sets clang-format on the output.
Register the unit. Open
projects/ores.shell/application/src/app/commands/{component}/{component}_commands.cppand add two lines, in alphabetical order with the others:#include "ores.shell/app/commands/{component}/{entity}_commands.hpp"
{entity}_commands::register_commands(root_menu, session, pagination);Delete the hand-written unit and its header for the entity in the same change, so the submenu is not registered twice.
Refresh the part file lists. The part declares
#+component_kind: adapter, so codegen owns its two file lists. The scan is a directory listing, and only this script writes it:projects/ores.codegen/venv/bin/python projects/ores.codegen/scripts/regenerate_cmake_component_files.py --component ores.shell.{component}Build and test.
./compass.sh build ores.shell.exe ./compass.sh test run -- -R ores.shell
The generated test file pins the arity check, the malformed token that names its field, and a valid token vector that reaches the transport. Read it before the smoke test, so a failure there is a code failure and not a surprise.
3. Tested by
Start ores.shell, connect, and exercise each subcommand interactively
against a local database. Every entity's cases carry the
{entity}_commands prefix, so ores.shell.{component}.tests --list-tests
gives a per-entity handle on a component's suite.
4. See also
- How do I test the shell? — the three levels that prove the new unit works.
- Shell entity patterns — class layout, the two shapes, file locations.
- compass-codegen-add-surface-entity — skill that drives this workflow.
- Entity lifecycle — layer ordering overview.