Skip to content

Commit 1a4fd52

Browse files
committed
✨ feat(plugin-help): get function name via get-func-name
1 parent 65b383b commit 1a4fd52

File tree

6 files changed

+17
-6
lines changed

6 files changed

+17
-6
lines changed

β€Žpackages/core/src/types/index.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type TransformFlags<F extends Record<string, FlagSchema>> = {
6161
: F[K]
6262
: F[K]
6363
};
64-
type TypeFlagWithDefault<C extends CommandRecord = CommandRecord, N extends keyof C = keyof C> = [C[N]] extends [unknown] ? { flags: Dict<any>; unknownFlags: Dict<any> } : TypeFlag<TransformFlags<NonNullable<C[N]["flags"]>>>;
64+
type TypeFlagWithDefault<C extends CommandRecord = CommandRecord, N extends keyof C = keyof C> = TypeFlag<TransformFlags<NonNullable<C[N]["flags"]>>>;
6565
type Raw<C extends CommandRecord = CommandRecord, N extends keyof C = keyof C> =
6666
TypeFlagWithDefault<C, N> & {
6767
parameters: string[]

β€Žpackages/plugin-help/package.jsonβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"dependencies": {
5858
"@clerc/toolkit": "workspace:*",
5959
"@clerc/utils": "workspace:*",
60+
"get-func-name": "^2.0.0",
6061
"picocolors": "^1.0.0"
6162
},
6263
"devDependencies": {

β€Žpackages/plugin-help/src/index.tsβ€Ž

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import pc from "picocolors";
99

1010
import type { Section } from "./renderer";
1111
import { render } from "./renderer";
12-
import { splitTable } from "./utils";
12+
import { splitTable, stringifyType } from "./utils";
1313

1414
const DELIMITER = pc.yellow("-");
1515

@@ -117,9 +117,7 @@ const showSubcommandHelp = (ctx: HandlerContext, command: string[] | SingleComma
117117
items.push(DELIMITER, flag.description);
118118
}
119119
if (flag.type) {
120-
const type = Array.isArray(flag.type)
121-
? `Array<${flag.type[0].name}>`
122-
: (flag.type as any).name;
120+
const type = stringifyType(flag.type);
123121
items.push(pc.gray(`(${type})`));
124122
}
125123
return items;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module "get-func-name" {
2+
const getFuncName: (fn: (...args: any[]) => any) => string;
3+
export default getFuncName;
4+
}

β€Žpackages/plugin-help/src/utils.tsβ€Ž

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import getFuncName from "get-func-name";
12
import { Table } from "@clerc/toolkit";
23

34
export const table = (...items: string[][]) => {
@@ -28,3 +29,9 @@ export const table = (...items: string[][]) => {
2829
export const splitTable = (...items: string[][]) => {
2930
return table(...items).toString().split("\n");
3031
};
32+
33+
export const stringifyType = (type: any) => {
34+
return Array.isArray(type)
35+
? `Array<${getFuncName(type[0])}>`
36+
: getFuncName(type);
37+
};

β€Žpnpm-lock.yamlβ€Ž

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)