Markdown docs and completion scripts
The same definition that drives parsing also produces a Markdown reference and shell completion scripts. Generate them from a small script and commit the output. That keeps them in step with the CLI.
Markdown
import { writeFileSync } from "node:fs";import path from "node:path";import { generateMarkdown } from "@staticbolt/args-parser";
import { listyCLI } from "../cli.ts";
const markdown = generateMarkdown(listyCLI);writeFileSync(path.join(import.meta.dirname, "..", "README.md"), markdown, "utf8");The output covers the CLI description, its options and arguments, and every subcommand that is not marked hidden. What each meta field contributes is described in Options and Subcommands. meta.markdownTitle sets the top heading. Without it, the heading is cliName.
Completion scripts
One function per shell, each returning the script as a string:
import { generateBashAutocompleteScript, generateFishAutocompleteScript, generatePowerShellAutocompleteScript, generateZshAutocompleteScript,} from "@staticbolt/args-parser";
import { listyCLI } from "../cli.ts";
writeFileSync("listy-autocomplete.sh", generateBashAutocompleteScript(listyCLI), "utf8");writeFileSync("listy-autocomplete.zsh", generateZshAutocompleteScript(listyCLI), "utf8");writeFileSync("listy-autocomplete.fish", generateFishAutocompleteScript(listyCLI), "utf8");writeFileSync("listy-autocomplete.ps1", generatePowerShellAutocompleteScript(listyCLI), "utf8");Installing them
| Shell | Where it goes |
|---|---|
| Bash | source <path>/listy-autocomplete.sh in ~/.bashrc or ~/.bash_profile |
| Zsh | source <path>/listy-autocomplete.zsh in ~/.zshrc |
| Fish | source <path>/listy-autocomplete.fish in ~/.config/fish/config.fish |
| PowerShell | . "<path>/listy-autocomplete.ps1" in the file that $profile points at |
Reopen the shell for the change to take effect.
The PowerShell script expects the CLI to be reachable as listy.ps1. Check with (Get-Command listy.ps1).Source.
Signatures are in Generators.
Building something else
If you want output that the built-in generators do not produce, read the definition through the metadata helpers instead of walking it by hand. They fill in every default and hand back a flat, fully resolved shape:
import { getCliMetadata } from "@staticbolt/args-parser";
const metadata = getCliMetadata(listyCLI);
for (const option of metadata.options) { console.log(option.nameAsArg, option.optional, option.defaultValueAsString);}See Metadata.