Skip to content

Commit 6372ea9

Browse files
committed
feat(parser): improve flag type display text
1 parent 95bcf9b commit 6372ea9

4 files changed

Lines changed: 11 additions & 6 deletions

File tree

packages/parser/src/flag-types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function Range(min: number, max: number): TypeFunction<number> {
4949

5050
return num;
5151
}) as TypeFunction<number>;
52-
fn.display = `${min}-${max}`;
52+
fn.display = `${min} - ${max}`;
5353

5454
return fn;
5555
}
@@ -75,7 +75,7 @@ export function Regex(
7575

7676
return value;
7777
}) as TypeFunction<string>;
78-
fn.display = description ?? pattern.toString();
78+
fn.display = description ?? `Regex: ${pattern.toString()}`;
7979

8080
return fn;
8181
}

packages/parser/test/flag-types.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe("flag-types", () => {
4141
const range = Range(1, 10);
4242

4343
expect(typeof range).toBe("function");
44-
expect(range.display).toBe("1-10");
44+
expect(range.display).toBe("1 - 10");
4545
});
4646

4747
it("should validate valid range", () => {
@@ -72,7 +72,7 @@ describe("flag-types", () => {
7272
const regex = Regex(/^\d+$/);
7373

7474
expect(typeof regex).toBe("function");
75-
expect(regex.display).toBe("/^\\d+$/");
75+
expect(regex.display).toBe("Regex: /^\\d+$/");
7676
});
7777

7878
it("should validate valid regex", () => {

packages/plugin-help/test/__snapshots__/plugin-help.test.ts.snap

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,13 @@ exports[`plugin-help > should show parameter types 1`] = `
391391
"test test - Test command
392392
393393
Usage
394-
[35m$ test test <param> <param2> [range] [flags][39m
394+
[35m$ test test <param> <param2> [range] [regex] [flags][39m
395395
396396
Parameters
397397
<param>
398398
<param2> a | b | c
399-
[range] 1-10
399+
[range] 1 - 10
400+
[regex] Regex: /^\\d+$/
400401
401402
Global Flags
402403
--help, -h Boolean Show help [default: false]",

packages/plugin-help/test/plugin-help.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ describe("plugin-help", () => {
5757
key: "[range]",
5858
type: Types.Range(1, 10),
5959
},
60+
{
61+
key: "[regex]",
62+
type: Types.Regex(/^\d+$/),
63+
},
6064
],
6165
})
6266
.parse(["test", "--help"]);

0 commit comments

Comments
 (0)