Options
All
  • Public
  • Public/Protected
  • All
Menu

typed-cli

badges

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

Usage example

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

Playground

You can test it without installing anything on your machine. Just go to the Demo(⚠️ 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

[Link to docs](link to docs)

Licence

MIT?

Index

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc