A tiny helper that lets your CLI args lead
Arglet is a small, joyful utility for CLI tools that helps merge configuration from CLI arguments.
Arglet is designed to be:
Arglet uses your configuration object as the source of truth. Only keys defined in that object are allowed, and values are parsed according to their existing type.
npm install arglet
# or
pnpm add arglet
# or
yarn add arglet
Get a fully-typed CLI configuration in one line.
import arglet from "arglet";
const config = arglet({
input: "src",
output: "dist",
watch: false,
});
node cli.js --input=lib --watch
Output:
{
input: "lib",
output: "dist",
watch: true
}
Define a configuration object and let Arglet update it using CLI arguments.
import arglet from "arglet";
const config = arglet({
name: "sriman",
age: 23,
debug: false,
});
Run your script:
node cli.js --name tene --age 25 --debug
Result:
{
name: "tene",
age: 25,
debug: true
}
Arglet respects the type defined in your config. Since
ageis a number in the schema,"25"is automatically cast to25.
Arglet parses values strictly based on the type in your configuration object.
| Schema Type | CLI Input | Result Type |
|---|---|---|
boolean |
--flag |
true |
boolean |
--no-flag |
false |
number |
--port=8080 |
number |
string |
--port=8080 |
"8080" |
string[] |
--tags=a,b |
string[] |
number[] |
--ids=1,2,3 |
number[] |
If the type is undefined or null, Arglet preserves the raw string value.
Boolean options support implicit enable/disable flags.
const config = arglet({
verbose: false,
cache: true,
});
--verbose # sets verbose → true
--no-cache # sets cache → false
❗ Boolean shortcuts are only allowed for boolean options. Using
--flagor--no-flagon non-boolean keys throws an error.
Non-boolean options must receive a value.
const config = arglet({
port: 3000,
});
--port 8080
# or
--port=8080
If a value cannot be parsed according to the schema type, Arglet throws an error.
Example:
--port hello
❌ Throws:
--port expects a number
Provide multiple values using a separator (, by default).
const config = arglet({
ids: [] as number[],
});
--ids=1,2,3
Result:
{
ids: [1, 2, 3];
}
If your schema is:
const config = arglet({
ids: [] as string[],
});
Then:
--ids=1,2,3
Result:
{
ids: ["1", "2", "3"];
}
You can customize the separator:
arglet({ ids: [] }, { arraySeparator: "|" });
--ids=1|2|3
Arglet supports deep configuration using dot paths.
const config = arglet({
server: {
host: "localhost",
port: 3000,
},
});
--server.host=0.0.0.0 --server.port=8080
Arglet will update nested properties while preserving types.
Only existing paths are allowed — unknown nested keys are ignored.
Flags that do not exist in your configuration object are ignored.
--unknown
Ignored (unless debug mode is enabled).
You can pass arguments directly (useful for tests or programmatic usage).
const config = arglet({ debug: false }, ["--debug"]);
Enable debug output to see how arguments are parsed and applied.
arglet({ debug: false }, { debug: true });
This logs:
Arglet is intentionally strict.
The following will throw errors:
--age # age is not boolean
--no-name # name is not boolean
--port hello # port expects number
This keeps CLI behavior predictable and safe.
import arglet from "arglet";
const config = arglet({
input: "src",
output: "dist",
watch: false,
});
console.log(config);
node cli.js --input=lib --watch
Arglet is not a full argument parser. It assumes you already control argument shape.
Its job is simple:
Predictable input → predictable output.