
Product
Socket Now Protects the Chrome Extension Ecosystem
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
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',
positionals: [
{
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.
cli-nano
is currently used in these other projects of mine (feel free to edit this list):
FAQs
Small command-line tool similar to `yargs` or `parseArgs` from Node.js to create a CLI accepting positional arguments, flags and options.
The npm package cli-nano receives a total of 2,845 weekly downloads. As such, cli-nano popularity was classified as 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.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.