Skip to content

Commit b25cebc

Browse files
committed
test docs and bun automaticly
1 parent 7440d1a commit b25cebc

6 files changed

Lines changed: 70 additions & 6 deletions

File tree

.github/workflows/test.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup Deno
17+
uses: denoland/setup-deno@v2
18+
with:
19+
deno-version: v2.x
20+
21+
- name: Setup Bun
22+
uses: oven-sh/setup-bun@v2
23+
with:
24+
bun-version: latest
25+
26+
- name: Run tests
27+
run: deno task test

deno.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "@sigma/parse",
3-
"version": "0.48.0",
3+
"version": "0.49.0",
44
"exports": "./mod.ts",
55
"license": "MIT",
66
"tasks": {
7-
"test": "deno test && bun test --preload ./bun-preload.ts"
7+
"test": "deno doc --lint mod.ts && deno test --doc && bun test --preload ./bun-preload.ts"
88
},
99
"imports": {
1010
"@std/assert": "jsr:@std/assert@^1.0.18"

mod.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ export {
7777
export type {
7878
ArgOptions,
7979
ArgumentMetadata,
80+
CollectionOptions,
8081
CommandInstance,
82+
CommandOptions,
8183
CommonOptions,
84+
DecoratorContext,
8285
OptDef,
8386
OptOptions,
8487
ParseOptions,
@@ -87,9 +90,10 @@ export type {
8790
PositionalDef as ArgumentDef,
8891
PropertyMetadata,
8992
SubCommand,
93+
SubCommandOptions,
9094
SupportedType,
9195
Validator,
92-
} from "./src/types.ts";
96+
} from "./src/index.ts";
9397

9498
// Export error handling utilities
9599
export {

src/decorators.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ export function addValidator(validator: Validator): (
7373
* 1. With a built-in or custom validator function (e.g., `@validate(range(1, 10))`)
7474
* 2. With a predicate function and custom error message (e.g., `@validate(val => val > 0, "must be positive")`)
7575
*
76-
* @param validatorOrPredicate - A validator function OR a predicate function
77-
* @param message - Error message (required only if using a predicate)
76+
* @param validator - A validator function
7877
* @returns A decorator function
7978
*/
8079
export function validate<T>(
@@ -83,13 +82,27 @@ export function validate<T>(
8382
_target: unknown,
8483
context: DecoratorContext,
8584
) => void;
85+
/**
86+
* Validate decorator for custom validation logic.
87+
*
88+
* @param predicate - Function that returns true if value is valid
89+
* @param message - Error message to show when validation fails
90+
* @returns A decorator function
91+
*/
8692
export function validate<T>(
8793
predicate: (value: T) => boolean,
8894
message: string,
8995
): (
9096
_target: unknown,
9197
context: DecoratorContext,
9298
) => void;
99+
/**
100+
* Validate decorator for custom validation logic.
101+
*
102+
* @param validatorOrPredicate - A validator function OR a predicate function
103+
* @param message - Error message (required only if using a predicate)
104+
* @returns A decorator function
105+
*/
93106
export function validate<T>(
94107
validatorOrPredicate: Validator | ((value: T) => boolean),
95108
message?: string,
@@ -121,10 +134,24 @@ export function command(
121134
target: T,
122135
ctx: ClassDecoratorContext,
123136
) => T;
137+
/**
138+
* Command decorator to mark a class as a CLI command or subcommand.
139+
*
140+
* @param target - The class constructor being decorated
141+
* @param ctx - The class decorator context
142+
* @returns The original or a modified class constructor
143+
*/
124144
export function command<T extends new () => unknown>(
125145
target: T,
126146
ctx: ClassDecoratorContext,
127147
): T;
148+
/**
149+
* Command decorator to mark a class as a CLI command or subcommand.
150+
*
151+
* @param optionsOrTarget - Either command options or the class constructor
152+
* @param _maybeCtx - Optional context (only present when used as a direct decorator)
153+
* @returns The decorator function or the decorated class
154+
*/
128155
export function command<T extends new () => unknown>(
129156
optionsOrTarget?: CommandOptions | T,
130157
_maybeCtx?: ClassDecoratorContext,

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export {
101101
type DecoratorContext,
102102
opt,
103103
subCommand,
104+
type SubCommandOptions,
104105
validate,
105106
} from "./decorators.ts";
106107
export {
@@ -119,6 +120,7 @@ export { printHelp } from "./help.ts";
119120
export {
120121
collectArgumentDefs,
121122
collectInstanceArgumentDefs,
123+
type CollectionOptions,
122124
extractTypeFromDescriptor,
123125
} from "./metadata.ts";
124126
export {

src/metadata.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import type {
1010
SupportedType,
1111
} from "./types.ts";
1212

13-
interface CollectionOptions {
13+
/**
14+
* Configuration options for metadata collection.
15+
*/
16+
export interface CollectionOptions {
17+
/** Whether to throw errors when types cannot be inferred */
1418
strict?: boolean;
1519
}
1620

0 commit comments

Comments
 (0)