MMOframework
Pourquoi l'IA Playground Bibliothèques Développeurs Agence
FR EN
Créer un projet en direct
Index
# Shell commands A command-line script (`admin.php`, `hub.php`, `scripts/admin.php`...) routes shell controllers (`aShellController`): each public method carrying a `#[Command]` (or an `#[InteractiveCommand]`, also offered by the interactive mode) is a command, `php admin.php [arguments] [--options]`. ## The manual Every shell controller answers `help` with the manual of the whole application (`ShellManual`), read from the commands' attributes -- whichever controller declares them: | Typed | Shows | |---|---| | `php admin.php help` (or `php admin.php --help`) | every command by group, one line each | | `php admin.php help edms gc` | the detail of `edms gc`: synopsis, description, arguments, options, examples | | `php admin.php edms gc --help` | the same, and the command is **not** run | | `php admin.php help dry-run` | the commands whose name, summary, description or options hold the word | | `php admin.php help -m` | the manual as json | | `php admin.php help --markdown=docs/commands.md` | the manual as markdown, written to that file | ## Documenting a command The attribute's info is a string (the summary: the recap's line) or an array: ```php use MMO\core\attributes\Command; use MMO\core\server\Route; class MyShell extends \MMO\core\classes\aShellController { #[Command([['const' => 'cpam']], [ 'summary' => 'update the CPAMs from configs/cpams.json', 'description' => "Each CPAM of the file updates the instance's one of its code, else is made.\n\nA CPAM no longer in the file is deleted, unless an employee is attached to it.", 'options' => [ 'dry-run' => 'list what would change, write nothing', 'database=' => 'another database of the server (with --dry-run only)', 'json|m' => 'the result as json', ], 'examples' => ['cpam --dry-run' => 'what would change'], 'group' => 'CPAM', 'see' => ['cpam-orphans'], ])] public function route_cpam(Route $route): void {} } ``` - `summary`: one line, what the command does, for the recap. - `description`: for the administrator: what it reads and writes, what it changes for good, when to run it, what to check before. Paragraphs are separated by an empty line (`\n\n`). - `options`: how each option is typed without its dashes => what it does. `dry-run` is a flag, `database=` takes a value, `m` is a letter (`-m`), `json|m` two spellings of one option (`--json, -m`). They are documentation only: what the method reads from the route is unchanged, so list every option it reads. - `examples`: command => what it does; `php {script}` is added in front of a command that does not start with `php`. - `group`: the recap's section, else the name of the package the method is written in (`mmo.edms`, `oviepro`). - `see`: related commands, by their words. The words of the command are the leading `const` of its body. An argument after them is a schema: give it a `title` (its name in the synopsis) and a `description`, `'required' => false` when it may be left out: ```php fragment #[Command([['const' => 'token'], ['type' => 'string', 'title' => 'username', 'description' => 'the account the token is for']], 'create a long lasting api token')] ``` ## A command refused A command refuses by throwing, as a route does: its status is the exception's code (`eServer(..., code: 400)`, `eRuntime(..., code: 404)`). Its message is the answer: when the level its exception is logged at is not shown -- a 404 is a notice, another 4xx a warning, so a script under `MMO_DEBUG` `error+` (the hub's `tools/mmo.php`) logs neither -- the application writes it on stderr, stdout kept for the command's answer (`-m`'s json): ```text $ php tools/mmo.php agent-login --user=nobody refused (404): unknown user [nobody]. ``` The script exits from the status (`\MMO\core\server\exitCode`, or 1 for any status from 400 as `tools/mmo.php` does). Until 2026-11 such a refusal printed nothing and only exited 1 (my.oviepro deploy #454). A message is read by whoever typed the command: never put a secret in it.