@christianjuth/ts-cli-generator
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-alpha.16 • Public • Published

@christianjuth/ts-cli-generator

Create a new CLI project

npx @christianjuth/ts-cli-generator

Resources

Demo

demo video

How it works

The following index.ts file:

import { call, CLI } from "@christianjuth/ts-cli-generator";

/**
 * Add two numbers
 */
function add(x: number, y: number) {
  console.log(x + y);
}

/**
 * Subtract two numbers
 */
function _subtract(x: number, y: number) {
  return x - y;
}

/**
 * Add then subtract as separate interactioins
 */
async function addSubtract(x: number, y: number) {
  console.log(x + y);
  // call allows you to call a cli function
  // from within another cli function
  console.log(await call(_subtract)());
}

/**
 * Get the length of a string
 */
function lengthOfString(str: string) {
  console.log(str.length);
}

export const cli: CLI = {
  add,
  addSubtract,
  lengthOfString,
  // underscore means function is available but hidden
  _subtract,
};

Will generate the following CLI:

name-of-cli CLI 0.0.0

Powered by @christianjuth/ts-cli-generator

Commands:
  add             	Add two numbers
  add-subtract    	Add then subtract as separate interactions
  length-of-string	Get the length of a string

Options:
  -i, --interactive	Run CLI in interactive mode
name-of-cli add
✔ param: x … 5
✔ param: y … 6
11
name-of-cli add-subtract
✔ param: x … 5
✔ param: y … 6
11
subtract
✔ param: x … 7
✔ param: y … 8
-1
name-of-cli length-of-string
✔ param: str … hello world
11

Readme

Keywords

Package Sidebar

Install

npm i @christianjuth/ts-cli-generator

Weekly Downloads

4

Version

1.0.0-alpha.16

License

MIT

Unpacked Size

293 kB

Total Files

61

Last publish

Collaborators

  • cjuth