Sade is a lightweight and powerful JavaScript library designed for building robust command-line interface (CLI) applications for Node.js. It distinguishes itself by providing a small API surface while offering essential features such as default commands, git-like subcommands, flexible option flags with aliases, type-casting for default option values, and sophisticated handling of required versus optional arguments. Sade also includes built-in command validation and automates the generation of helpful documentation, including version and usage text. The current stable version is 1.8.1, and the package sees regular, feature-driven releases, often including patches and minor enhancements like Deno support and integrated TypeScript definitions. It aims to offer a smooth developer and user experience with minimal overhead, making it a strong alternative to more heavyweight CLI frameworks.
npm install sadeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a basic CLI application with Sade, including program-wide options, two distinct commands (`build` and `greet`), command-specific options, and argument parsing with actions.
Upgrade to `sade@1.7.3` or newer. Avoid directly accessing `process.argv` within action handlers; instead, rely on the arguments and options passed to the `action()` function.
Always ensure options preceding the command name are correctly paired (e.g., `--config my-config.js`) or place options after the command name for clarity. For boolean flags, they must not appear immediately before the command name if the command name could be interpreted as a value.
Uninstall `@types/sade` from your project dependencies. Ensure your `tsconfig.json` includes `sade` in `types` if you're using global types, or import types directly: `import type { Handler } from 'sade';`.Define all global options, version, and description using `prog.option()`, `prog.version()`, etc., before defining any specific commands with `prog.command()`.
Ensure you are using `sade@1.7.3` or newer. Do not rely on side effects of `process.argv` mutation. Access arguments and options via the `action()` callback parameters.
Check your command definition to ensure all required arguments are clearly marked (`<arg>`). Inform users to provide all necessary arguments, which will also be highlighted in the automatically generated help text.
When using options before the command name, ensure they are always explicitly paired with a value (e.g., `--config my.js`). For boolean flags, place them after the command name or ensure they are followed by a non-command argument.
Ensure you are using `import sade from 'sade';` for ESM contexts (like modern Node.js modules or bundlers) or `const sade = require('sade');` for CommonJS environments. Sade supports both since v1.8.0, but context matters.No dependency data recorded yet.