Skip to content

Commit 4b2b808

Browse files
committed
@dep/command@2.0.0
1 parent 08f74d4 commit 4b2b808

13 files changed

Lines changed: 464 additions & 508 deletions

File tree

README.md

Lines changed: 50 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,72 @@
1-
# @deb/command 🛠️
1+
# @dep/command 🛠️
22

3-
> A lightweight, type-safe CLI command builder for Deno, Node.js, and browsers.
3+
> A type-safe CLI command builder for Deno and Node.js, enabling easy creation of commands with arguments, options, subcommands, and handlers.
44
5-
## [![JSR version](https://jsr.io/badges/@deb/command)](https://jsr.io/@deb/command)
5+
## [![JSR version](https://jsr.io/badges/@dep/command)](https://jsr.io/@dep/command)
66

77
## Features ✨
88

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
9+
- 🔒 Type-safe definitions for arguments and options
10+
- 📚 Support for nested subcommands and aliases
11+
- ⚙️ Automatic handling of --help and --version flags
12+
- Built-in validation for configurations and inputs
13+
- 🔄 Variadic arguments and options for flexible parsing
14+
- 📦 Seamless integration with Deno and Node.js environments
1515

1616
---
1717

1818
## Installation 📦
1919

2020
- **Deno**:
21-
2221
```bash
23-
deno add jsr:@deb/command
22+
deno add jsr:@dep/command
2423
```
24+
- **Node.js (18+)**:
2525

26-
- **Node.js (18+) or Browsers**:
2726
```bash
28-
pnpm i jsr:@dep/table
27+
npx jsr add @dep/command
2928
```
29+
3030
Then import as an ES module:
31+
3132
```typescript
32-
import { Command } from '@deb/command';
33+
import { Command } from '@dep/command';
3334
```
3435

3536
---
3637

3738
## Usage 🎯
3839

39-
### CLI 💻
40+
### CLI 💻 <!-- if available -->
4041

41-
```ts
42-
// cli.ts
43-
import { Command, CommandError } from '@deb/command';
42+
This package is a library for building CLI tools. Once you've defined your command, you can run it from the command line using Deno or Node.js. For example, save the script below as `mycli.ts` and execute it with `deno run mycli.ts [args]` or `node mycli.js [args]`.
4443

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-
})
44+
Example command execution:
45+
46+
```bash
47+
deno run mycli.ts input.txt --output output.txt
48+
```
49+
50+
### API 🧩
51+
52+
Use the `Command` class to build and configure your CLI. Here's a basic example:
53+
54+
```typescript
55+
import { Command } from '@dep/command';
56+
57+
const cmd = new Command()
58+
.name('mycli')
59+
.description('A simple CLI tool example')
60+
.version('1.0.0')
61+
.argument('input', { description: 'Input file path' })
5462
.option('--output', {
5563
kind: 'value',
56-
shortFlag: '-o',
5764
description: 'Output file path',
65+
shortFlag: '-o',
5866
})
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);
67+
.handler(({ args, options }) => {
68+
console.log('Input file:', args.input);
69+
console.log('Output file:', options.output);
6670
});
6771

6872
try {
@@ -77,57 +81,18 @@ try {
7781
}
7882
```
7983

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 🌿
84+
For more advanced usage, including subcommands:
11585

116-
```ts
117-
import { Command, CommandError } from '@deb/command';
86+
```typescript
87+
import { Command } from '@dep/command';
11888

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...');
89+
const cmd = new Command()
90+
.name('mycli')
91+
.description('CLI with subcommands')
92+
.command('sub', 'Subcommand description')
93+
.argument('arg', 'Subcommand argument')
94+
.handler(({ args }) => {
95+
console.log('Subcommand arg:', args.arg);
13196
});
13297

13398
try {
@@ -142,42 +107,7 @@ try {
142107
}
143108
```
144109

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-
```
110+
Run with `mycli sub value` to execute the subcommand.
181111

182112
---
183113

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dep/command",
3-
"version": "1.0.0",
3+
"version": "2.0.0",
44
"exports": "./src/main.ts",
55
"compilerOptions": {
66
"strict": true

jsr.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@dep/command",
3-
"version": "1.0.0",
4-
"description": "A lightweight, type-safe CLI command builder for Deno, Node.js, and browsers.",
3+
"version": "2.0.0",
4+
"description": "A type-safe CLI command builder for Deno and Node.js, enabling easy creation of commands with arguments, options, subcommands, and handlers.",
55
"exports": "./src/main.ts",
66
"author": {
77
"name": "Estarlin R.",

0 commit comments

Comments
 (0)