Clipanion is a TypeScript-first framework for building robust and type-safe command-line interfaces (CLIs). It leverages TypeScript's powerful type system to define command arguments and options, providing compile-time validation and autocompletion, significantly reducing common runtime errors associated with CLI parsing. The package is currently at version `4.0.0-rc.4`, indicating active development towards a stable major release with a strong emphasis on modern JavaScript and TypeScript practices. A key differentiator is its zero runtime dependencies (beyond its peer dependency `typanion` for runtime type validation), resulting in extremely small bundle sizes. It integrates deeply with `typanion` to derive runtime validators directly from static TypeScript types, providing a seamless development experience for complex CLI applications. This approach contrasts with other CLI libraries that often rely on separate schema definitions or less integrated type checking.
npm install clipanionVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a basic Clipanion CLI with a 'hello' command, utilizing `Option.String` for argument parsing with a default value and integrating built-in help and version commands. It showcases the ESM-first approach and the use of `Command.String()` for validation.
Review the v4 migration guide (when available) and adapt command definitions to use the new `Option` and `Command.<Type>()` fluent API for validators. Ensure `typanion` is correctly installed as a peer dependency.
Configure your project to use ES Modules by adding `"type": "module"` to your `package.json` and using `import` statements. If a CJS environment is strictly required, ensure your build pipeline (e.g., Babel, TypeScript compiler) correctly transpiles ESM to CJS, or consider sticking to Clipanion v3 if CJS compatibility is paramount.
Always install `typanion` alongside `clipanion`: `npm install typanion` or `yarn add typanion`. Ensure the installed version is compatible with your Clipanion version, generally matching the `*` peer dependency requirement.
Ensure you register the built-in commands: `cli.register(Builtins.HelpCommand); cli.register(Builtins.VersionCommand);`. Consider adding `Builtins.DefinitionsCommand` as well for advanced introspection.
For Clipanion v4, ensure `typanion` is installed (`npm i typanion`) and that you're correctly using `Option.String('--name', { validator: Command.String() })`. For Clipanion v3, argument validation was handled differently and `Command.String()` was not part of the public API for options.First, ensure `clipanion` is installed (`npm i clipanion`). If it is, configure your `package.json` with `"type": "module"` for ESM, or ensure your build system transpiles ESM imports to CommonJS correctly if you must remain in a CJS environment.
Replace `require()` calls with `import` statements. Ensure your project's `package.json` has `"type": "module"` or that the file explicitly uses the `.mjs` extension for ES Module interpretation.