Docs Packages
@procedures/cli-run
npm install @procedures/cli-run
client-cli gives one procedure, cli.run. It starts a command of the mark CLI in a new Node process and gives its output. Thus a program can use any mark command.
cli.run is not a tool of the MCP server: it starts any mark command, shell exec too. As a tool, it gives back the shell access that the tool list keeps out (deep dive CLI-5).
Use#
import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/cli-run"; // registers cli.run and shell.*
const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
// The same as: mark lib new my-package --preset lib
const result = await client.exec(["cli", "run"], {
path: ["lib", "new"],
positional: ["my-package"],
args: { preset: "lib" },
});
console.log(result.success, result.stdout);
From the command line:
node packages/mark/dist/cli.js cli run lib scan
Input#
| Field | Type | Function |
|---|---|---|
path | string[] | The path of the mark command, for example ["lib", "new"] |
positional | string[] | The arguments after the path |
args | Record<string, string | number | boolean> | The flags. { name: "x" } gives --name x. true gives --name. false gives no flag. |
cwd | string | The folder of the command |
timeout | number | The time limit in milliseconds |
Output#
| Field | Type | Function |
|---|---|---|
exitCode | number | The exit code of mark |
stdout, stderr | string | The output of mark |
success | boolean | True when the exit code is 0 |
duration | number | The time in milliseconds |
cli.run does not throw for a failed command. It gives success: false and the error in stderr.
How it works#
cli.runfindspackages/mark/dist/cli.jsin the workspace that contains it. Without a build ofmark, it fails with a message.- It makes an argument list: the path, the positional arguments, then the flags.
- It starts
nodewith that list throughshell.run, with no shell. The values cannot start other commands.
mark itself uses a warm CLI server when one is safe to use: the same folder, the same build, and the token of its lockfile.
Limits#
- A flag value that starts with
-reachesmarkas a separate word, somarkcan read it as a flag. argscannot givefalseto a flag whose default istrue. Use the procedure directly instead.