Generates usage spec for CLIs written with yargs.
npm install @usage-spec/yargsimport yargs from "yargs";
import { generate } from "@usage-spec/yargs";
const y = yargs([])
.scriptName("mycli")
.version("1.0.0")
.option("verbose", { alias: "v", type: "boolean", description: "Be verbose" })
.option("file", { alias: "f", type: "string", description: "Input file" })
.command("add <file>", "Add a file", () => {})
.command("remove", "Remove files", () => {});
console.log(generate(y));Generates a usage spec in KDL format from a yargs Argv instance.
Alias for generate().
Generates a usage spec in JSON format.
Converts a yargs Argv to the Spec data structure.
This package uses yargs internal APIs (getOptions(), getInternalMethods()) to extract command and option metadata. These APIs are not part of the stable public API and may change between yargs versions.
MIT