Skip to content

createCommandSchema

Generated reference page for the createCommandSchema function export.

Signatures

ts
function createCommandSchema(definition: CommandDefinition): CommandSchema;
ParameterTypeDescription
definitionCommandDefinitionCommand name plus optional flags, args, and subcommands.

Members

Members

createCommandSchema

Create a CommandSchema from a plain definition object.

Most consumers should prefer command(), which returns a CommandBuilder with type inference. createCommandSchema() is the low-level escape hatch for tooling that composes schemas as data.

Flags, args, and subcommands are normalized recursively, so an already-built schema fed back in produces a deep-equal schema.

Flag spellings are checked across the whole tree, so a definition whose names, aliases, or negated spellings collide with each other or with a propagated ancestor flag is rejected here. Both flags still parse under their canonical names, so what a collision costs is the shared spelling. Help advertises it on both flags and the parser answers it with one of them. Args go through the same invariants CommandBuilder.arg enforces. These are the checks the CommandBuilder applies as flags, args, and subcommands are registered.

ts
(definition: CommandDefinition): CommandSchema;

Examples

ts
const schema = createCommandSchema({
  name: 'deploy',
  description: 'Ship the build',
  flags: { force: { kind: 'boolean' } },
  args: [{ name: 'target', schema: { kind: 'string' } }],
});

See Also

Released under the MIT License.