@ocfx/cli
v1.0.12
Published
Type safe parsing of CLI parameters As opposed to other CLI parsers, @ocfx/cli returns type safe parameters and therefore allow for better compilation and intellisense @ocfx/cli is not a framework for managing the whole CLI application lifecycle, inst
Readme
Description
Type safe parsing of CLI parameters As opposed to other CLI parsers, @ocfx/cli returns type safe parameters and therefore allow for better compilation and intellisense @ocfx/cli is not a framework for managing the whole CLI application lifecycle, instead it focuses on parsing argv in a type safe manner
Installation
Stable version:
npm install @ocfx/cliSimple Example
import { Schema, read } from "@ocfx/cli";
const cli = read({
name: Schema.string(),
});
console.log("Hello " + cli.name);$ ./main.js --name World
Hello WorldComplex Example
import { Schema, read } from "@ocfx/cli";
const cli = read({
name: Schema.string(), // Parameter --name is required
id: Schema.number(), // Parameter --id is required (must be a number)
verbose: Schema.boolean("v", false), // Parameter --v is optional
emails: Schema.stringArray("email") // Parameter --email is a list of strings. For example, "abc cde efg"
});
console.log("Name: " + cli.name);
console.log("ID: " + cli.id);
console.log("Verbose: " + cli.verbose);
console.log("Emails: " + cli.emails);$ ./main.js --name Roni --id 1 --email "[email protected] [email protected]"
Name: Roni
ID: 1
Verbose: true
Emails: [email protected],[email protected]