Observed since 20 Oct, 22:16 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
@0x-jerry/silver
Let writing CLI like writing document.
Let writing CLI like writing a document.
pnpm i @0x-jerry/silver
import { silver } from "@0x-jerry/silver";
const cli = silver`
v1.0.0 @autocomplete
my-cli [file], A CLI that writes like a document. ${mainAction}
-t --test @type:defaultValue, Test autocomplete.
-o --output @string, Output file path.
up/upgrade <dir> [...extra] #stopEarly, Upgrade something. ${upgradeAction}
-f --force @bool, Force upgrade.
`;
// Register custom completion types
cli.type("type", () => ["value1", "value2", "value3"]);
function mainAction([file], options) {
console.log("file:", file, "options:", options);
}
function upgradeAction([dir, ...extra], options) {
console.log("dir:", dir, "extra:", extra, "options:", options);
}
Silver uses a template literal to define your CLI. Here's the full syntax:
v1.0.0 @autocomplete @manual
| Token | Description |
|---|---|
v1.0.0 | Version declaration (must be at the top) |
@autocomplete | Enables complete subcommand for shell autocomplete |
@manual | Prevents auto-execution; call cli.execute(argv) manually |
commandName/alias [param] <reqParam> [...restParam] #stopEarly, Description text. ${actionFn}
| Part | Example | Description |
|---|---|---|
| Name | install | Command name (alphanumeric + _) |
| Alias | install/i | Shorthand alias via / |
| Optional param | [name] | Optional positional parameter |
| Required param | <name> | Required positional parameter |
| Rest param | [...items] | Collects remaining arguments as array |
| Flag | #stopEarly | Command flag (see below) |
| Description | , Install packages. | Text after comma is the description |
| Action | ${myFn} | Function to call when command is executed |
Command flags:
| Flag | Description |
|---|---|
#stopEarly | Stop parsing options after the first non-option argument |
-s --string @type, Description.
| Part | Example | Description |
|---|---|---|
| Short name | -s | Single-letter alias |
| Long name | --string | Full option name |
| Type | @string | Option type (see below) |
| Description | , Description. | Text after comma |
[@type:name] // typed optional parameter
<@type:name> // typed required parameter
[...@type|_files:name] // typed rest param with file completion
Types are registered via cli.type(name, getValues). Built-in types include bool, boolean, number, string. Special completion types _files and _dirs enable shell-native file/directory completion.
Set @autocomplete at the program level to enable shell completion.
| Shell | Command |
|---|---|
| zsh | source <(your-cli complete zsh) |
| PowerShell | Invoke-Expression (your-cli complete powershell | Out-String) |
For persistent setup, add the output to your shell's config file (.zshrc or PowerShell profile).
cli.type("env", () => ["development", "production", "staging"]);
// Async types
cli.type("remote-branch", async () => {
const res = await fetch("https://api.example.com/branches");
return res.json();
});
// With descriptions (displayed in some shells)
cli.type("format", () => [
{ label: "json", desc: "JSON output" },
{ label: "yaml", desc: "YAML output" },
]);
| Type | Description |
|---|---|
_files | File path completion (shell-native) |
_dirs | Directory path completion (shell-native) |
These can be combined with custom types: @custom|_files.
silver (default export)function silver(template: TemplateStringsArray, ...tokens: any[]): Silver;
Parses the template and optionally auto-executes with process.argv.
Silver class| Method | Description |
|---|---|
type(name, getValues) | Register a completion type (sync or async) |
execute(argv) | Execute the CLI with the given arguments |
parse(raw, ...tokens) | Parse a template literal programmatically |
import {
silver,
BuiltinType, // enum: File = '_files', Dir = '_dirs'
type CompletionGroup, // { name: string, values: string[] }
type CompletionOutput, // { groups: CompletionGroup[] }
type Command,
type CmdOption,
type CmdParameter,
type Program,
type CmdAction,
type ActionParsedArgs,
ProgramFlag,
CommandFlag,
} from "@0x-jerry/silver";
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
ohm-jsEnvironment{
"local_name": "ohm-js",
"alias": false,
"peer_metadata": null
} | ^17.1.0 | runtime |
minimistEnvironment{
"local_name": "minimist",
"alias": false,
"peer_metadata": null
} | ^1.2.8 | runtime |
picocolorsEnvironment{
"local_name": "picocolors",
"alias": false,
"peer_metadata": null
} | ^1.1.0 | runtime |
@0x-jerry/utilsEnvironment{
"local_name": "@0x-jerry/utils",
"alias": false,
"peer_metadata": null
} | ^3.0.0 | runtime |
tsupEnvironment{
"local_name": "tsup",
"alias": false,
"peer_metadata": null
} | ^8.2.4 | development |
vitestEnvironment{
"local_name": "vitest",
"alias": false,
"peer_metadata": null
} | ^2.1.1 | development |
typescriptEnvironment{
"local_name": "typescript",
"alias": false,
"peer_metadata": null
} | ^5.6.2 | development |
@ohm-js/cliEnvironment{
"local_name": "@ohm-js/cli",
"alias": false,
"peer_metadata": null
} | ^2.0.0 | development |
@types/nodeEnvironment{
"local_name": "@types/node",
"alias": false,
"peer_metadata": null
} | ^22.5.5 | development |
@types/minimistEnvironment{
"local_name": "@types/minimist",
"alias": false,
"peer_metadata": null
} | ^1.2.5 | development |
@0x-jerry/x-releaseEnvironment{
"local_name": "@0x-jerry/x-release",
"alias": false,
"peer_metadata": null
} | ^2.2.2 | development |
@vitest/coverage-v8Environment{
"local_name": "@vitest/coverage-v8",
"alias": false,
"peer_metadata": null
} | ^2.1.1 | development |
Source distribution
{
"shasum": "118099c01bcc34c03619ec5193afdabc176f7dbe",
"tarball": "https://registry.npmjs.org/@0x-jerry/silver/-/silver-1.1.1.tgz",
"fileCount": 5,
"integrity": "sha512-KWSGomQ2RLE2pMYz1Dl3jbH8jR3iaHv5xaU1dTxXz6et17IAiuoNFRFLMQr2HOqTGnGl6HNjDsy/BB5P6UfHIA==",
"signatures": [
{
"sig": "MEUCIEw8AiRMvZ8SrqlEWUYmsawUmzrK1jX9fovdqmMVBhPpAiEAmYA+1PDmWGFgbSAI5icZ58oJDCxCJWCdt4n7IPYF7Ew=",
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
}
],
"unpackedSize": 34133
}Observed since 20 Oct, 22:16 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:691e222fb9cd4e4f128742a63f2e24c5581531aa50cc81cc9a58bb5fd7557e10