Skip to content

Commit 08f74d4

Browse files
committed
@dep/command@1.0.0
0 parents  commit 08f74d4

24 files changed

Lines changed: 1532 additions & 0 deletions

.github/workflows/publish.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Publish
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
id-token: write
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Publish package
16+
run: npx jsr publish

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/dist
2+
/temp
3+
/.pnp
4+
.pnp.js
5+
/coverage
6+
/out/
7+
.DS_Store
8+
*.pem
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
.pnpm-debug.log*
13+
.env*.local

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MIT License
2+
3+
Copyright (c) 2025 Estarlin R
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
p:
2+
deno run publish
3+
b:
4+
deno run build
5+
s:
6+
deno run start
7+
d:
8+
deno run dev
9+
l:
10+
deno run lint
11+
f:
12+
deno run fmt
13+
t:
14+
deno run check-types

README.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# @deb/command 🛠️
2+
3+
> A lightweight, type-safe CLI command builder for Deno, Node.js, and browsers.
4+
5+
## [![JSR version](https://jsr.io/badges/@deb/command)](https://jsr.io/@deb/command)
6+
7+
## Features ✨
8+
9+
- 🧩 **Type-safe options & arguments** – Full TypeScript inference for flags, values, and variadics
10+
- 🌳 **Nested subcommands** – Build complex CLI hierarchies with ease
11+
- 🚦 **Smart parsing** – Supports `--flag`, `-f`, `--option=value`, variadic args, and more
12+
- 📋 **Auto-generated help & version** – Built-in `--help` and `--version` with beautiful formatting
13+
-**Validation & defaults** – Enforce required fields, choices, and default values at parse time
14+
- 🔒 **Zero dependencies** – Pure TypeScript, works everywhere
15+
16+
---
17+
18+
## Installation 📦
19+
20+
- **Deno**:
21+
22+
```bash
23+
deno add jsr:@deb/command
24+
```
25+
26+
- **Node.js (18+) or Browsers**:
27+
```bash
28+
pnpm i jsr:@dep/table
29+
```
30+
Then import as an ES module:
31+
```typescript
32+
import { Command } from '@deb/command';
33+
```
34+
35+
---
36+
37+
## Usage 🎯
38+
39+
### CLI 💻
40+
41+
```ts
42+
// cli.ts
43+
import { Command, CommandError } from '@deb/command';
44+
45+
const cli = new Command()
46+
.name('my-cli')
47+
.description('Does something awesome')
48+
.version('2.0.0')
49+
.option('--dry-run', {
50+
kind: 'flag',
51+
shortFlag: '-n',
52+
description: 'Don’t execute, just simulate',
53+
})
54+
.option('--output', {
55+
kind: 'value',
56+
shortFlag: '-o',
57+
description: 'Output file path',
58+
})
59+
.option('--tags', { kind: 'variadic', description: 'List of tags' })
60+
.argument('files', { kind: 'variadic', description: 'Files to process' })
61+
.handler(async ({ options, args }) => {
62+
console.log('Dry run:', options.dryRun);
63+
console.log('Output:', options.output);
64+
console.log('Tags:', options.tags);
65+
console.log('Files:', args.files);
66+
});
67+
68+
try {
69+
await clit.run(); // (defaults tokens Deno.args | `process.argv.slice(2)`)
70+
} catch (err) {
71+
if (err instanceof CommandError) {
72+
console.error(`\nError: ${err.message}\n`);
73+
cmd.help();
74+
Deno.exit(1); //or process.exit(1);
75+
}
76+
throw err;
77+
}
78+
```
79+
80+
Run it:
81+
82+
```bash
83+
deno run -A cli.ts src/*.ts --dry-run -o dist/ --tags build prod
84+
# → Dry run: true
85+
# → Output: dist/
86+
# → Tags: [ 'build', 'prod' ]
87+
# → Files: [ 'src/index.ts', 'src/utils.ts' ]
88+
```
89+
90+
Use `--help`:
91+
92+
```bash
93+
deno run -A cli.ts --help
94+
```
95+
96+
```
97+
Usage: my-cli [files...] [options]
98+
99+
Does something awesome
100+
101+
Arguments:
102+
files... Files to process
103+
104+
Options:
105+
--dry-run, -n Don’t execute, just simulate
106+
--output, -o Output file path
107+
--tags List of tags
108+
--help, -h Show help
109+
--version, -v Show version
110+
```
111+
112+
---
113+
114+
### Subcommands 🌿
115+
116+
```ts
117+
import { Command, CommandError } from '@deb/command';
118+
119+
const cli = new Command()
120+
.name('git')
121+
.description('Git-like CLI')
122+
.command('commit', 'Record changes')
123+
.option('--message', { kind: 'value', shortFlag: '-m' })
124+
.option('--all', { kind: 'flag', shortFlag: '-a' })
125+
.handler(({ options }) => {
126+
console.log('Committing with message:', options.message);
127+
})
128+
.command('push', 'Push changes')
129+
.handler(() => {
130+
console.log('Pushing...');
131+
});
132+
133+
try {
134+
await clit.run(); // (defaults tokens Deno.args | `process.argv.slice(2)`)
135+
} catch (err) {
136+
if (err instanceof CommandError) {
137+
console.error(`\nError: ${err.message}\n`);
138+
cmd.help();
139+
Deno.exit(1); //or process.exit(1);
140+
}
141+
throw err;
142+
}
143+
```
144+
145+
```bash
146+
deno run -A git.ts commit -m "fix bug" --all
147+
# → Committing with message: fix bug
148+
```
149+
150+
---
151+
152+
### API 🧩
153+
154+
```ts
155+
const cmd = new Command()
156+
.name('build')
157+
.option('--watch', { kind: 'flag' })
158+
.argument('entry', { kind: 'value' });
159+
160+
// Parse custom tokens
161+
const input = cmd.parse(['app.ts', '--watch']); // (defaults tokens Deno.args | `process.argv.slice(2)`)
162+
console.log(input.options.watch); // true
163+
console.log(input.args.entry); // "app.ts"
164+
```
165+
166+
---
167+
168+
## Advanced Options
169+
170+
```ts
171+
.option('--mode', {
172+
kind: 'value',
173+
choices: ['development', 'production'],
174+
default: 'development'
175+
})
176+
.option('--config', {
177+
kind: 'inline', // --config=path
178+
optional: true
179+
})
180+
```
181+
182+
---
183+
184+
## License 📄
185+
186+
MIT License – see [LICENSE](LICENSE) for details.
187+
188+
**Author:** Estarlin R ([estarlincito.com](https://estarlincito.com))

deno.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@dep/command",
3+
"version": "1.0.0",
4+
"exports": "./src/main.ts",
5+
"compilerOptions": {
6+
"strict": true
7+
},
8+
"imports": {
9+
"@/": "./src/",
10+
"@dep/table": "jsr:@dep/table@^1.0.1"
11+
},
12+
"tasks": {
13+
"start": "deno run --allow-net src/main.ts",
14+
"build": "deno run --allow-read src/build.ts",
15+
"dev": "deno run --allow-env --allow-net --watch src/main.ts",
16+
"check-types": "deno check src/**/*.ts && deno publish --check",
17+
"lint": "deno lint",
18+
"fmt": "deno fmt",
19+
"prepublish": "deno lint && deno fmt",
20+
"publish": "deno task prepublish && jsr publish ./"
21+
},
22+
"lint": {
23+
"rules": {
24+
"tags": ["recommended"]
25+
}
26+
}
27+
}

deno.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jsr.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "@dep/command",
3+
"version": "1.0.0",
4+
"description": "A lightweight, type-safe CLI command builder for Deno, Node.js, and browsers.",
5+
"exports": "./src/main.ts",
6+
"author": {
7+
"name": "Estarlin R.",
8+
"email": "dev@estarlincito.com",
9+
"url": "https://estarlincito.com"
10+
},
11+
"homepage": "https://github.com/dep-ts/command#readme",
12+
"repository": "https://github.com/dep-ts/command",
13+
"bugs": "https://github.com/dep-ts/command/issues",
14+
"keywords": [
15+
"cli",
16+
"command",
17+
"parser",
18+
"arguments",
19+
"options",
20+
"flags",
21+
"type-safe",
22+
"typescript",
23+
"deno",
24+
"node",
25+
"subcommands",
26+
"help",
27+
"version",
28+
"variadic",
29+
"inline-options"
30+
],
31+
"license": "MIT",
32+
"publish": {
33+
"include": ["src", "LICENSE", "README.md"],
34+
"exclude": ["**/tests/**"]
35+
}
36+
}

0 commit comments

Comments
 (0)