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-VVel6gMrZnHccRBY5gVmTQL11KiDWigwpfZn7vf/VK4L9a98dmfB9eBJmhLk/O8mPHv3MGqFaofrFTj/zIhRQA==",
"shasum": "1ded6c26756a9a03b9f577dc00d40b09bb2af59a",
"tarball": "https://registry.npmjs.org/3h-cli/-/3h-cli-1.5.0.tgz",
"fileCount": 4,
"unpackedSize": 9229,
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbQKMACRA9TVsSAnZWagAA094QAJ0bWM7uPFUaxYnVGsf/\noG1/t1D4Evqto9ItMB9dvPOJRSnKAr13gSjkZDvzAtasbhswkN1vg+V6jzIE\nZ3UwpiLXaWwPKYqAYEAgGNa8uS67CsA9XIvctpXopfJidtw0vRagVxqMm8ms\nHQ8+Y00LkFAnCsR52m15dGvLmhy7Xu7H+K9Qj3057w3M97bw4qfXWQbgS3CJ\n7cPQ+8uHAJ1lqUBoiczkZZ6wRoR2czbQ3bAcTgKYLhNmGu5+KbOIdGrhhLMp\ndLrsM1OjOpcrtQlBTSa889Zcx4hEFxr+DiMBmGe8+f4z+ywak1KMY+Yd2YJ+\nsA8QT0RI+PjBN4K1QEwNpNrrVbfbipRG/6LQPUGadJxncqWXVjPEyKEvn0QA\nLqiOeoFH40h/Ln4oyIOcS8J6JN1VyBeSPl7NThmlOT8J8X5QjZPmxyVTtCKx\nykMlE+NqjNzhjzfYKAOwvgnpfG+DsawrNa8ToGl2ilReqWm80YMEOuHqhxob\nxocjRM7Tkbl7gtwWp7iYePdDIc+y1KWA+elECHqUywxn/WPlhIsh7g+L0Jp7\nYAbGYfMzdbml6KuYtvG6zMJnRquVLDLRphiolE0bGYbOO1wEZCJhyHtKRl5J\nQemnT36pFhzbDB5OVB/XAra1N8eSNgAA7822JmqieM9+xqcq6zxd3GjB3ntq\n0ZfA\r\n=jg5F\r\n-----END PGP SIGNATURE-----\r\n",
"signatures": [
{
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
"sig": "MEQCIGTKTkZsYdzL6m51YZkJChQ5CzvJ/2oPejfpaLvBRLFnAiBdT3bXSJxKMNd+lSZ35RUneu0q+ADLzj0JWhtign3C9Q=="
}
]
}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:e81bccf044f3e9db6165466a73bf357cb06eb7a85b4173a3c8be5c54177e037c