Skip to content
A type-safe wrapper around commander.js with excellent type inference.
TypeScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.gitignore
README.md
package.json
tsconfig.json
yarn.lock

README.md

@soundtype/commander

A type-safe wrapper around commander.js with excellent type inference.

Usage

import { program } from '@soundtype/commander';

const myProgram = program('my-app', '1.0.0')
  .option({
    name: 'bool',
    description: 'this is a boolean',
    default: false,
  })
  .option({
    name: 'num',
    description: 'this is a number',
    default: undefined,
    parse: str => {
      const value = parseInt(str, 10);
      if (Number.isNaN(value)) throw new Error('This is not an int');
      return value;
    },
  })
  .variadic({ name: 'positional', required: true })
  .build();

// result type is `{ num?: number, bool: boolean, positional: string[] }`
const result = myProgram.parse(process.argv);

Local Development

This project was bootstrapped with TSDX.

Below is a list of commands you will probably find useful.

npm start or yarn start

Runs the project in development/watch mode. Your project will be rebuilt upon changes. TSDX has a special logger for you convenience. Error messages are pretty printed and formatted for compatibility VS Code's Problems tab.

Your library will be rebuilt if you make edits.

npm run build or yarn build

Bundles the package to the dist folder. The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).

npm test or yarn test

Runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.

You can’t perform that action at this time.