0.0.5 • Published 2 years ago

@kkx-org/args v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@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));
				},
			});
		},
	});
});
0.0.5

2 years ago

0.0.4

2 years ago

0.0.1

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago