# typed-cli

> [![Coverage Status](https://coveralls.io/repos/github/int0h/typed-cli/badge.svg?branch=master)](https://coveralls.io/github/int0h/typed-cli?branch=master)

Latest version **1.2.0** (published 2021-12-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install typed-cli
pnpm add typed-cli
yarn add typed-cli
bun add typed-cli
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2021-12-03 |
| First published | 2019-09-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 169.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | int0h |
| Keywords | cli, terminal, argv, argument, args, command |

## Links

- npm: https://www.npmjs.com/package/typed-cli
- npm.io page: https://npm.io/package/typed-cli

## Dependencies (7)

- [chalk](https://npm.io/package/chalk.md) ^4.1.2
- [tabtab](https://npm.io/package/tabtab.md) git+https://github.com/int0h/tabtab.git#ba938481a264fcc60a21a3288b32485f28e7fcca
- [@types/node](https://npm.io/package/@types/node.md) ^16.11.6
- [string-argv](https://npm.io/package/string-argv.md) ^0.3.1
- [yargs-parser](https://npm.io/package/yargs-parser.md) ^20.2.9
- [@types/string-argv](https://npm.io/package/@types/string-argv.md) ^0.1.0
- [@types/yargs-parser](https://npm.io/package/@types/yargs-parser.md) ^20.2.1

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2021-12-03
- 1.1.0-rc — 2021-11-02
- 1.0.1-rc — 2021-11-02
- 1.0.0-rc — 2021-11-02
- 0.2.6 — 2020-03-14
- 0.2.5 — 2020-03-14
- 0.2.3 — 2019-09-30
- 0.2.2 — 2019-09-30
- 0.2.1 — 2019-09-28
- 0.2.0 — 2019-09-28
- 0.1.1 — 2019-09-22
- 0.1.0 — 2019-09-22

## README

# typed-cli

[![Coverage Status](https://coveralls.io/repos/github/int0h/typed-cli/badge.svg?branch=master)](https://coveralls.io/github/int0h/typed-cli?branch=master)

![typed-cli logo](./logo128.png)

A library to help you create **type-safe** CLI's fast and simple.

# Project state

This project is still alive and maintained. But it is not in active development.

# Usage example

```typescript
import {cli, option} from 'typed-cli';
import app from './app';

const {options} = cli({
    options: {
        env: option.oneOf(['dev', 'prod'] as const)
            .alias('e')
            .required()
            .description('app environment'),
        port: option.int
            .alias('p')
            .default(80)
            .description('port'),
    }
});

// port: number
// env: 'dev' | 'prod'
const {port, env} = options;


const DB_HOSTS = {
    dev: 'localhost:1234',
    prod: '1.2.3.4:9999',
} as const;

// Type safe!
// no "No index signature with a parameter of type 'string'" kind of errors
// because typeof env is 'dev' | 'prod'
app.run({
    db: DB_HOSTS[env],
    port
});
```

This code will behave like this:

![terminal-demo](./demo.gif)

# Playground

You can test it without installing _anything_ on your machine. Just go to the

**[Interactive Demo](https://int0h.github.io/typed-cli-pg/index.html)**

(⚠️it's about 20Mb of traffic).
It has _interactive_ terminal and code editor, you can change the samples and see how it reacts.

# Key features

- **Type safety**
- input validation (customizable)
- help generation
- printing reports for invalid data
- **tab completions**
- input data transformation
- support for **commands**

# Documentation
The docs can be found here: [https://int0h.github.io/typed-cli-docs/](https://int0h.github.io/typed-cli-docs/)

---
_Source: https://npm.io/package/typed-cli · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
