1.0.0-alpha.16 • Published 2 years ago
@christianjuth/ts-cli-generator v1.0.0-alpha.16
@christianjuth/ts-cli-generator
Create a new CLI project
npx @christianjuth/ts-cli-generator
Resources
Demo
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
1.0.0-alpha.16
2 years ago
1.0.0-alpha.15
2 years ago
1.0.0-alpha.14
2 years ago
1.0.0-alpha.13
2 years ago
1.0.0-alpha.12
2 years ago
2.0.0-alpha.0
2 years ago
1.0.0-alpha.11
2 years ago
1.0.0-alpha.10
2 years ago
1.0.0-alpha.9
2 years ago
1.0.0-alpha.8
2 years ago
1.0.0-alpha.7
2 years ago
1.0.0-alpha.6
2 years ago
1.0.0-alpha.5
2 years ago
1.0.0-alpha.4
2 years ago
1.0.0-alpha.3
2 years ago
1.0.0-alpha.2
2 years ago
1.0.0-alpha.1
2 years ago
1.0.0-alpha.0
2 years ago
0.0.1-alpha.8
2 years ago
0.0.1-alpha.7
2 years ago
0.0.1-alpha.6
2 years ago
0.0.1-alpha.5
2 years ago
0.0.1-alpha.4
2 years ago
0.0.1-alpha.3
2 years ago
0.0.1-alpha.2
2 years ago
0.0.1-alpha.1
2 years ago
0.0.1-alpha.0
2 years ago