Skip to content

Metadata

The metadata helpers read a definition and return a flat, fully resolved description of it. They fill in defaults, turn missing text into an empty string, and turn missing lists into empty arrays. You never have to check for undefined.

This is what the built-in help and Markdown generators use. Reach for it when you want to build output of your own.

import { getCliMetadata } from "@staticbolt/args-parser";
const metadata = getCliMetadata(listyCLI);
for (const option of metadata.options) {
console.log(option.nameAsArg, option.optional ? "(optional)" : "", option.description);
}

Functions

Function Returns
getCliMetadata(cliDefinition) CliMetadata
getSubcommandsMetadata(subcommands) SubcommandMetadata[]
getOptionsMetadata(options) OptionMetadata[]
getArgumentsMetadata(arguments) ArgumentMetadata[]

getCliMetadata already includes the other three. You only need the rest when you are working with a piece of a definition on its own.

CliMetadata

Field Type Description
name string The CLI name.
title string meta.markdownTitle, or the name.
description string Empty when not set.
descriptionMarkdown string Empty when not set.
usage string Empty when not set.
example string Empty when not set.
allowPositionals boolean
options OptionMetadata[] Empty when there are none.
arguments ArgumentMetadata[] Empty when there are none.
subcommands SubcommandMetadata[] Empty when there are none.

SubcommandMetadata

Same as CliMetadata, minus title and subcommands, plus:

Field Type Description
name string The subcommand name.
aliases string[] Empty when there are none.
placeholder string Empty when not set.
hidden boolean Whether it is left out of docs and help.

OptionMetadata

Field Type Description
name string The name as written in code.
nameAsArg string The flag, for example --input-dir.
aliases string[] Aliases as written in code.
aliasesAsArgs string[] Aliases as flags, for example ["-i"].
placeholder string Empty when not set.
description string Empty when not set.
descriptionMarkdown string Empty when not set.
example string Empty when not set.
defaultValue unknown The schema's default, if it has one.
defaultValueAsString string The same value, ready to print. Empty when there is none.
optional boolean Resolved from the schema, or from meta.optional.
hidden boolean Whether it is left out of docs and help.
schema Schema The original schema.

ArgumentMetadata

Same as OptionMetadata, minus the flag and alias fields and placeholder. name is the argument name, already respecting meta.name.