Skip to content

Commit 5b9378b

Browse files
committed
refactor: rename @option to @opt for brevity
- Rename @option decorator to @opt - Rename OptionDef to OptDef and OptionOptions to OptOptions - Update all metadata keys from 'option' to 'opt' - Update all internal variables from 'optionDefs' to 'optDefs' - Update all examples, tests, and documentation
1 parent 33f0133 commit 5b9378b

23 files changed

Lines changed: 405 additions & 420 deletions

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ decorators and inheritance.
66
## Features
77

88
- **Perfect Type Safety** - Fully typed results based on your class definitions.
9-
- **Unified Decorators** - Simplify configuration with `@option` and `@arg`
9+
- **Unified Decorators** - Simplify configuration with `@opt` and `@arg`
1010
objects.
1111
- **Explicit Flags** - Clear distinction between CLI options and internal state.
1212
- **Subcommands** - Hierarchical command structure with full type safety.
@@ -17,7 +17,7 @@ decorators and inheritance.
1717
## Quick Start
1818

1919
```typescript
20-
import { arg, Args, cli, option } from "@sigma/parse";
20+
import { Args, cli, opt } from "@sigma/parse";
2121

2222
@cli({ name: "calculator", description: "A simple calculator" })
2323
class Calculator extends Args {
@@ -27,7 +27,7 @@ class Calculator extends Args {
2727
@arg({ type: "number", description: "second number", required: true })
2828
b!: number;
2929

30-
@option({ description: "operation to perform" })
30+
@opt({ description: "operation to perform" })
3131
operation = "add";
3232
}
3333

@@ -45,14 +45,14 @@ console.log(`${args.a} ${args.operation} ${args.b} = ...`);
4545
Your main command class must extend `Args` to get the static `parse` method:
4646

4747
```typescript
48-
import { Args, cli, option } from "@sigma/parse";
48+
import { Args, cli, opt } from "@sigma/parse";
4949

5050
@cli({ name: "myapp", description: "My application" })
5151
class MyApp extends Args {
52-
@option({ description: "Enable verbose logging", short: "v" })
52+
@opt({ description: "Enable verbose logging", short: "v" })
5353
verbose = false;
5454

55-
@option({ description: "Port number", type: "number" })
55+
@opt({ description: "Port number", type: "number" })
5656
port = 8080;
5757
}
5858

@@ -66,14 +66,14 @@ Subcommands are plain classes (no need to extend `Args`). Link them using
6666
`@subCommand`:
6767

6868
```typescript
69-
import { Args, cli, command, option, subCommand } from "@sigma/parse";
69+
import { Args, cli, opt, subCommand } from "@sigma/parse";
7070

7171
@command
7272
class ServeCommand {
73-
@option({ description: "Port to serve on" })
73+
@opt({ description: "Port to serve on" })
7474
port = 3000;
7575

76-
@option({ description: "Enable development mode", short: "d" })
76+
@opt({ description: "Enable development mode", short: "d" })
7777
dev = false;
7878
}
7979

@@ -98,7 +98,7 @@ if (args.serve) {
9898

9999
### Property Decorators
100100

101-
- `@option(options)` - Mark a property as a CLI flag (`--flag`).
101+
- `@opt(options)` - Mark a property as a CLI flag (`--flag`).
102102
- `description`: Help text.
103103
- `type`: Explicit type (`"string"`, `"number"`, `"boolean"`, `"string[]"`,
104104
`"number[]"`).
@@ -123,7 +123,7 @@ if (args.serve) {
123123
**Explicitly Required** (must be provided on CLI):
124124

125125
```typescript
126-
@option({ type: "string", required: true })
126+
@opt({ type: "string", required: true })
127127
apiKey!: string;
128128
```
129129

@@ -147,19 +147,19 @@ verbose = false; // becomes -v, --verbose
147147
### Built-in Validators
148148

149149
```typescript
150-
import { Args, cli, oneOf, option, pattern, range } from "@sigma/parse";
150+
import { Args, cli, opt, pattern, range } from "@sigma/parse";
151151

152152
@cli({ name: "example" })
153153
class Example extends Args {
154-
@option()
154+
@opt()
155155
@range(1, 100)
156156
score = 50;
157157

158-
@option()
158+
@opt()
159159
@oneOf(["dev", "prod"])
160160
env = "dev";
161161

162-
@option()
162+
@opt()
163163
@pattern(/^[a-z]+$/)
164164
user = "admin";
165165
}

bench/bench.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// deno-lint-ignore-file no-import-prefix
22
import { parseArgs } from "jsr:@std/cli@1/parse-args";
3-
import { arg, Args, cli, command, option, subCommand } from "../src/index.ts";
3+
import { arg, Args, cli, command, opt, subCommand } from "../src/index.ts";
44
import { Command } from "jsr:@cliffy/command@1.0.0-rc.8";
55

66
const args = ["deno", "run", "-A", "script.ts", "hello world"];
@@ -15,7 +15,7 @@ Deno.bench("Args API", { group: "parse" }, () => {
1515
@arg({ description: "script to run", type: "string" })
1616
script?: string;
1717

18-
@option({ short: "A", type: "boolean" })
18+
@opt({ short: "A", type: "boolean" })
1919
A?: boolean;
2020

2121
@arg({ description: "script arguments", rest: true, type: "string[]" })

examples/cli_api_example.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,45 @@ import {
1212
cli,
1313
command,
1414
oneOf,
15-
option,
15+
opt,
1616
range,
1717
subCommand,
1818
} from "../mod.ts";
1919

2020
// Simple example with basic options
2121
@cli({ name: "calculator", description: "A simple calculator application" })
2222
class Calculator extends Args {
23-
@option({
23+
@opt({
2424
description: "First number to operate on",
2525
type: "number",
2626
required: true,
2727
})
2828
a!: number;
2929

30-
@option({
30+
@opt({
3131
description: "Second number to operate on",
3232
type: "number",
3333
required: true,
3434
})
3535
b!: number;
3636

37-
@option({
37+
@opt({
3838
description: "Operation to perform",
3939
})
4040
@addValidator(oneOf(["add", "subtract", "multiply", "divide"]))
4141
operation = "add";
4242

43-
@option({ description: "Show detailed output" })
43+
@opt({ description: "Show detailed output" })
4444
verbose = false;
4545
}
4646

4747
// Subcommands are plain classes (no need to extend Args)
4848
@command
4949
class BuildCommand {
50-
@option({ description: "Enable production optimizations" })
50+
@opt({ description: "Enable production optimizations" })
5151
production = false;
5252

53-
@option({ description: "Output directory" })
53+
@opt({ description: "Output directory" })
5454
output = "dist";
5555

5656
@arg({ description: "Project directory to build", type: "string" })
@@ -59,24 +59,24 @@ class BuildCommand {
5959

6060
@command
6161
class ServeCommand {
62-
@option({ description: "Port to serve on" })
62+
@opt({ description: "Port to serve on" })
6363
@addValidator(range(1, 65535))
6464
port = 3000;
6565

66-
@option({ description: "Enable development mode" })
66+
@opt({ description: "Enable development mode" })
6767
dev = false;
6868

69-
@option({ description: "Host to bind to" })
69+
@opt({ description: "Host to bind to" })
7070
host = "localhost";
7171
}
7272

7373
// Main app with subcommands (extends Args)
7474
@cli({ name: "buildtool", description: "A project build and development tool" })
7575
class BuildTool extends Args {
76-
@option({ description: "Enable verbose logging" })
76+
@opt({ description: "Enable verbose logging" })
7777
verbose = false;
7878

79-
@option({ description: "Configuration file to use" })
79+
@opt({ description: "Configuration file to use" })
8080
config = "build.config.js";
8181

8282
@subCommand(BuildCommand)
@@ -105,11 +105,11 @@ class FileProcessor extends Args {
105105
})
106106
includes?: string[];
107107

108-
@option({ description: "Processing operation" })
108+
@opt({ description: "Processing operation" })
109109
@addValidator(oneOf(["copy", "transform", "validate"]))
110110
operation = "copy";
111111

112-
@option({ description: "Enable verbose output" })
112+
@opt({ description: "Enable verbose output" })
113113
verbose = false;
114114
}
115115

@@ -248,7 +248,7 @@ console.log(`
248248
NEW API DESIGN:
249249
@cli({ name: "myapp", description: "My app" })
250250
class MyApp extends Args { // Main command extends Args
251-
@option({ description: "Verbose mode" })
251+
@opt({ description: "Verbose mode" })
252252
verbose = false;
253253
254254
@subCommand(ServeCommand)
@@ -257,10 +257,10 @@ class MyApp extends Args { // Main command extends Args
257257
258258
@command
259259
class ServeCommand { // Subcommands are plain classes
260-
@option({ description: "Port" })
260+
@opt({ description: "Port" })
261261
port = 3000;
262262
263-
@option({ description: "Dev mode" })
263+
@opt({ description: "Dev mode" })
264264
dev = false;
265265
}
266266

examples/error-handling.ts

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@
55
* more robust CLI applications that don't always exit on errors.
66
*/
77

8-
import {
9-
Args,
10-
cli,
11-
command,
12-
isParseError,
13-
option,
14-
subCommand,
15-
} from "../mod.ts";
8+
import { Args, cli, command, isParseError, opt, subCommand } from "../mod.ts";
169

1710
// Example 1: Default behavior (exits on errors)
1811
console.log("=== Example 1: Default Behavior (Process Exit) ===");
@@ -23,10 +16,10 @@ try {
2316
description: "App with default error handling",
2417
})
2518
class DefaultConfig extends Args {
26-
@option()
19+
@opt()
2720
port: number = 8080;
2821

29-
@option()
22+
@opt()
3023
debug: boolean = false;
3124
}
3225

@@ -46,10 +39,10 @@ try {
4639
exitOnHelp: false,
4740
})
4841
class GracefulConfig extends Args {
49-
@option()
42+
@opt()
5043
port: number = 8080;
5144

52-
@option()
45+
@opt()
5346
debug: boolean = false;
5447
}
5548

@@ -95,10 +88,10 @@ try {
9588
onHelp: handleHelp,
9689
})
9790
class CustomConfig extends Args {
98-
@option({ description: "Server port number" })
91+
@opt({ description: "Server port number" })
9992
port: number = 8080;
10093

101-
@option({ description: "Enable debug logging" })
94+
@opt({ description: "Enable debug logging" })
10295
debug: boolean = false;
10396
}
10497

@@ -112,13 +105,13 @@ console.log("\n=== Example 4: Server Application ===");
112105

113106
@command
114107
class StartCommand {
115-
@option({ description: "Port to listen on" })
108+
@opt({ description: "Port to listen on" })
116109
port: number = 3000;
117110

118-
@option({ description: "Host to bind to" })
111+
@opt({ description: "Host to bind to" })
119112
host: string = "localhost";
120113

121-
@option({
114+
@opt({
122115
description: "Configuration file path",
123116
required: true,
124117
type: "string",
@@ -128,7 +121,7 @@ class StartCommand {
128121

129122
@command
130123
class StopCommand {
131-
@option({ description: "Force stop without graceful shutdown" })
124+
@opt({ description: "Force stop without graceful shutdown" })
132125
force: boolean = false;
133126
}
134127

@@ -181,7 +174,7 @@ class ServerApp {
181174
@subCommand(StopCommand)
182175
stop?: StopCommand;
183176

184-
@option({ description: "Global verbose flag" })
177+
@opt({ description: "Global verbose flag" })
185178
verbose: boolean = false;
186179
}
187180

@@ -253,10 +246,10 @@ class _TestRunner {
253246
exitOnHelp: false,
254247
})
255248
class TestConfig extends Args {
256-
@option()
249+
@opt()
257250
port: number = 8080;
258251

259-
@option()
252+
@opt()
260253
debug: boolean = false;
261254
}
262255

@@ -309,13 +302,13 @@ class _ConfigManager {
309302
},
310303
})
311304
class AppConfig extends Args {
312-
@option({ description: "Database URL", required: true, type: "string" })
305+
@opt({ description: "Database URL", required: true, type: "string" })
313306
dbUrl!: string;
314307

315-
@option({ description: "API port" })
308+
@opt({ description: "API port" })
316309
port: number = 3000;
317310

318-
@option({ description: "Environment" })
311+
@opt({ description: "Environment" })
319312
env: string = "development";
320313
}
321314

0 commit comments

Comments
 (0)