Current collected state Current
Observed since 20 Oct, 19:43 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
3h-cli
A cli lib.
A cli program lib.
npm i 3h-cli
/* my-cli.js */
#!/usr/bin/env node
const { Program } = require('3h-cli');
const program = new Program('my-cli', {
title: 'This is my-cli.',
});
program
.action({
name: 'foo',
help: 'action foo'
})
.action({
name: 'bar',
help: 'action bar'
})
.option({
name: '--baz',
alias: '-b',
value: '<val>',
help: 'option baz'
})
.option({
name: '--help',
alias: '-h',
help: 'show help info\nlike this'
})
.rest({
value: '[args...]',
help: 'other args'
})
.parse(process.argv)
.then(args => {
console.log('received actions:', args.actions);
console.log('received options:', args.options);
console.log('other args:', args.rest);
console.log('--------------------------------');
if (args.options.has('--help')) {
return program.help();
}
}, err => {
console.error(err);
process.exit(1);
})
$ ./my-cli.js --help
received actions: []
received options: Map { '--help' => [] }
other args: []
--------------------------------
This is my-cli.
Usage:
my-cli <action> [options] -- [args...]
actions:
foo action foo
bar action bar
Options:
--baz, -b <val> option baz
--help, -h show help info
like this
-- [args...] other args
The API reference is written in TypeScript style.
class Args {
constructor(
actions: string[],
options: Map<string, string[]>,
rest: string[]
);
readonly actions: string[];
readonly options: Map<string, string[]>;
readonly rest: string[];
/**
* A utility method that returns
* the specific option if it exists
* or an empty array otherwise
*/
getOption(name: string): string[];
}
interface Args {
actions: string[];
options: Map<string, string[]>;
rest: string[];
}
/**
* Parse arguments from the given array of strings
* @example
* ```js
* const rawArgs = ['foo', '--bar', '-ac', '666', '--', '10', '11'],
* optionAliases = new Map([['-a', '--baz']]);
*
* console.log(parse(rawArgs, optionAliases));
* // {
* // actions: ['foo'],
* // options: Map {
* // '--bar' => [],
* // '--baz' => [],
* // '-c' => ['666']
* // },
* // rest: ['10', '11']
* // }
* ```
*/
function parse(
rawArgs: string[],
optionAliases?: Map<string, string>
): Args;
interface ActionDefinition {
name: string;
help?: string;
}
interface OptionDefinition {
name: string;
alias?: string | null;
value?: string;
help?: string;
}
interface RestDefinition {
value: string;
help?: string;
}
type ProgramOptions = Partial<{
title: string;
helpInfoIndent: number;
helpInfoGap: number;
ignoreUnknownActions: boolean;
ignoreUnknownOptions: boolean;
}>;
class Program {
constructor(name: string, options?: Readonly<ProgramOptions>);
/**
* The name/title of the program
* (displayed in built-in help info)
*/
readonly name: string;
title: string;
/**
* Style parameters of built-in help info
*/
helpInfoIndent: number;
helpInfoGap: number;
/**
* Whether to ignore undefined actions/options
* (By default, undefined options will
* cause the parsing promise to be rejected
* but unknown actions won't)
*/
ignoreUnknownActions: boolean;
ignoreUnknownOptions: boolean;
/**
* Register a action, an option or rest options
*/
action(definition: ActionDefinition): this;
option(definition: OptionDefinition): this;
rest(description: RestDefinition | null): this;
/**
* Parse the arguments
* @returns a promise solved with parsed args on success
* or rejected on unknown actions/options
*/
parse(rawArgs: string[]): Promise<Args>;
/**
* Display built-in help info
* (the help info is generated from action and
* option definitions; you can append other help
* info after this like the example below)
* @example
* ```js
* program.parse(process.argv)
* .then(args => {
* if (args.options.has('--help')) {
* program.help();
* console.log('\nExamples');
* console.log(' my-cli foo --bar');
* } else {
* // ...
* }
* }, err => {
* // ...
* });
* ```
*/
help(): void;
}
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
@types/nodeEnvironment{
"local_name": "@types/node",
"alias": false,
"peer_metadata": null
} | ^9.4.6 | development |
Source distribution
{
"integrity": "sha512-KgEo/94L7Trs03u0ZuGuQm65vt3vp1PBLneX+EhnRpQSJc7LyZMl0M4CX3xhwktly+4h0wdTVR2uA71Vb/dt0g==",
"shasum": "e5444c73dbb77aaa4b03c8aad9c87a67888da007",
"tarball": "https://registry.npmjs.org/3h-cli/-/3h-cli-1.0.6.tgz",
"fileCount": 7,
"unpackedSize": 17615,
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa9jpNCRA9TVsSAnZWagAA+csP/RaPMalDwWOnK2qPaVvi\n4MxC3L3GyQwjN4f6UV3Qf70VyVHCcmmOGpxBSaCaUQDvPlvwJUfQp+wxe+Ll\nbTnZfUcS9uxhs8mab8iyK6K+WxEqzCNCsqOE4iEVHFbzHOlmKD2BF2qkCo8p\nTHZvVKg7Cr7UUoM+NoFrSszdjyNp/8NSKcNGL2gq1RCSPfPu39je4u+WZm4c\n2MguFJJjnzQwj7k8EnKaxNmTkQcDXFqR31ScAiiXkksnW8jNlsaeGu3VkxZI\nn4OzJi8hiTdKa/HyIMY7WaRc7fdQeN7xShjTIshNNgVwXRV/Ef9sprTo/jxF\nHjOgVG9vOFj/nBalUThp8LXeyUNTgI7CPe8toMQpEuLzdsRpv19RO5cqWQmM\nRQu91/ILBMiUD12osSG/N6qy2zzVLIyk/M1tXPIXCNsrKE+2C4mZNS4H8O0g\nbaXCH4IUs4CMChJOuyVMDiINekDhAybR3p7v2mTJt0KwkBW7gbb4Gr2QPzIi\nD9ouyLMjFn9xsNUahShXcNZ4u0yDWaBr49yYg+6XrU/khX78v69q+2aMB5j+\nn/PEmoMr1siChRk7FKvH6Xrgd9Bc/Dt8qLLMbzi/y9mnxmwzHiJ8pao8N2Lv\nsQnw1RErqorziWeuu/L34eoAOl0cEK3Eh77gQGqZf6t3TT1FmxliTxrzCY9j\nDpa7\r\n=1ZK8\r\n-----END PGP SIGNATURE-----\r\n",
"signatures": [
{
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
"sig": "MEUCID8oERk54uZ59X8SxpKxCNR9Vzi2IViMwtfWiZ0u8NO7AiEAnxd6/a8efhsOrGG8FHJn/afQadtDci2kc7mTsuEc3AI="
}
]
}Shared repository data · GitHub
Public sponsor counts have not been collected. These signals belong to the repository owner.
github · 1 observations shown. Missing days are unknown.
| Date / source period | Value | Observed at |
|---|---|---|
| 2026-10-22 | 0 | 2026-10-22T13:31:36.0535911Z |
Observed since 20 Oct, 19:43 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:c4e970e34b923bca235864041296019ac31e51ed0cea60622c9f68ea89298b8a