0.0.5 • Published 3 years ago
@kkx-org/args v0.0.5
@kkx-org/args
Parse CLI arguments, create CLI apps.
Installation
npm install @kkx-org/args
Usage
import { App, HelpGenerators } from "@kkx-org/args";
const app = new App({
id: "test-app",
description: "test app",
flags: [
{
id: "test",
description: "test option",
options: ["true"],
keys: ["-t", "--test"],
acceptsValue: false,
},
],
positional: [
{
id: "message",
},
],
subcommands: [
{
id: "test",
description: "test subcommand",
keys: ["test", "t"],
},
],
});
// Automatically add options for --help and -h
app.autoHelp();
const helpGen = HelpGenerators.DefaultHelpGenerator();
app.run((cmd) => {
let { message } = cmd.positional;
cmd.matchCommand({
_default: (cmd) => {
if (cmd.flags.help) {
console.log("help");
}
},
_help: (cmd) => {
console.log(helpGen.generate(cmd));
},
test: (cmd) => {
cmd.matchCommand({
_default: (cmd) => {
console.log(message ? message[0] : "no message passed in");
},
_help: (cmd) => {
console.log(helpGen.generate(cmd));
},
});
},
});
});