Host entry

Run the Astryx CLI from your own command-line tool: the inputs `runHostedCli` takes, what it returns, and when the process ends instead.

Start a run

A tool that carries the CLI for its own users starts one run per process with runHostedCli from @astryxdesign/cli/host. The run behaves as the CLI's own command does with the same arguments in the same folder, and the commands it prints start with your tool's command.

javascript
import {runHostedCli} from '@astryxdesign/cli/host';
​
const {status} = await runHostedCli({
argv: process.argv.slice(2),
cwd: process.cwd(),
cliCommand: 'acme astryx',
});
process.exitCode = status;

Options

OptionDefaultMeaning
argvnoneThe command-line arguments, without the command name.
cwdthe process's working folderThe folder the run works in. It must exist.
cliCommandthe package manager's nameThe command your users type, such as acme astryx: a non-blank single line of at most 120 characters, with no surrounding spaces.
declinedProjectClinoneWhy you did not run the project's own CLI, such as untrusted: a non-blank single line of at most 120 characters. That CLI then never runs.
rootsnoneYour package sets, in order of preference: folders whose node_modules each hold a CLI, the Core of the same release, and integrations. A run never installs a release; it takes the release a project needs from the first set that holds it.
integrationsnoneIntegrations you approve for use outside a project, by package name.
discoverSourcesnoneYour own discover sources. npx @astryxdesign/cli discover reports each as the host's.

Result and errors

  • It resolves with {status, packages}: the exit status the CLI's own command would exit with, and each package the run used, with its version and whether it came from the project or a package set.
  • When another release answers from one of your package sets through its own host entry, that entry runs in the same process with the same inputs, and the call resolves with its result.
  • It rejects with a TypeError, before anything runs, for an unknown option or an invalid value, and with an Error when a run already started in the process. Start each run in a new process.

When the process ends instead

Like the CLI's own command, a run ends the process with its exit status, and the call never resolves, when it:

  • prints help or the version (--help, -h, help, --version, -V, --version --json);
  • rejects the command line, such as an unknown command or option;
  • reports an error it stops on, including every error in --json mode;
  • meets an unexpected error;
  • hands the run to another CLI's own command: the project's CLI when you pass no declinedProjectCli, or a package set whose CLI has no host entry.