
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Mini command-line tool similar to `yargs` or `parseArgs` from Node.js that accepts positional arguments, flags and options.
Simple library to create command-line tool (aka CLI) which is quite similar to Yargs
, it is as configurable as Yargs but is a fraction of its size. The library is also inspired by NodeJS parseArgs()
but is again more configurable so that we really get what we would expect from a more complete CLI builder.
--camelCase
and --kebab-case
--no-
prefix--version
--help
required
optionsdefault
valuesnpm install cli-nano
#!/usr/bin/env node
import { type Config, parseArgs } from 'cli-nano';
const config: Config = {
command: {
name: 'serve',
description: 'Start a server with the given options',
positional: [
{
name: 'input',
description: 'serving files or directory',
type: 'string',
variadic: true, // 1 or more
required: true,
},
{
name: 'port',
type: 'number',
description: 'port to bind on',
required: false,
default: 5000, // optional default value
},
],
},
options: {
dryRun: {
alias: 'd',
type: 'boolean',
description: 'Show what would be done, but do not actually start the server',
default: false, // optional default value
},
exclude: {
alias: 'e',
type: 'array',
description: 'pattern or glob to exclude (may be passed multiple times)',
},
rainbow: {
type: 'boolean',
alias: 'r',
description: 'Enable rainbow mode',
default: true,
},
verbose: {
alias: 'V',
type: 'boolean',
description: 'print more information to console',
},
up: {
type: 'number',
description: 'slice a path off the bottom of the paths',
default: 1,
},
display: {
alias: 'D',
required: true,
description: 'a required display option',
}
},
version: '0.1.6',
};
const args = parseArgs(config);
console.log(args);
// do something with parse arguments, for example
// startServer(args);
# Show help guide (created by reading CLI config)
serve --help
# Show version (when defined)
serve --version
# Uses default port 5000
serve dist/index.html
# With required and optional positionals
serve index1.html index2.html 8080 -D value
# With boolean and array options
serve index.html 7000 --dryRun --exclude pattern1 --exclude pattern2 -D value
# With negated boolean
serve index.html 7000 --no-dryRun -D value
# With short aliases
serve index.html 7000 -d -e pattern1 -e pattern2 -D value
# With number option
serve index.html 7000 --up 2 -D value
default
property in an option or positional argument to specify a value if the user does not provide one.
{ type: 'boolean', default: false }
{ name: 'port', type: 'number', default: 5000 }
variadic: true
for arguments that accept multiple values.required: true
to enforce presence of an option.--no-flag
to set a boolean option to false
.--exclude a --exclude b
).alias
for short flags (e.g., -d
for --dryRun
).See examples/ for more usage patterns.
FAQs
Mini command-line tool similar to `yargs` or `parseArgs` from Node.js that accepts positional arguments, flags and options.
The npm package cli-nano receives a total of 262 weekly downloads. As such, cli-nano popularity was classified as not popular.
We found that cli-nano demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.