Skip to content

Commit 090c25f

Browse files
committed
refactor: remove getVersion
1 parent 5bfdadb commit 090c25f

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

packages/plugin-help/src/index.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function showHelp (ctx: HandlerContext, { examples, notes }: ShowHelpOptions) {
7878
showSubcommandHelp(ctx);
7979
return;
8080
}
81-
cli._name && console.log(`${pc.green(cli._name)} ${getVersion(cli._version)}`);
81+
cli._name && console.log(`${pc.green(cli._name)} ${gracefulVersion(cli._version)}`);
8282
if (cli._description) {
8383
console.log(cli._description);
8484
newline();
@@ -116,7 +116,7 @@ function showSubcommandHelp (ctx: HandlerContext) {
116116
if (!commandToShowHelp) {
117117
throw new NoSuchCommandError(`No such command: ${commandName}`);
118118
}
119-
console.log(`${pc.green(`${cli._name}.${commandToShowHelp.name}`)} ${getVersion(cli._version)}`);
119+
console.log(`${pc.green(`${cli._name}.${commandToShowHelp.name}`)} ${gracefulVersion(cli._version)}`);
120120
commandToShowHelp.description && console.log(commandToShowHelp.description);
121121
newline();
122122
console.log(pc.yellow("USAGE:"));
@@ -135,7 +135,7 @@ function showSubcommandHelp (ctx: HandlerContext) {
135135
function showSingleCommandHelp (ctx: HandlerContext) {
136136
const { cli } = ctx;
137137
const singleCommand = cli._commands[SingleCommand]!;
138-
console.log(`${pc.green(`${cli._name} ${getVersion(cli._version)}`)}`);
138+
console.log(`${pc.green(`${cli._name} ${gracefulVersion(cli._version)}`)}`);
139139
singleCommand.description && console.log(singleCommand.description);
140140
newline();
141141
console.log(pc.yellow("USAGE:"));
@@ -150,7 +150,3 @@ function showSingleCommandHelp (ctx: HandlerContext) {
150150
}
151151
}
152152
}
153-
154-
function getVersion (version: string) {
155-
return version ? gracefulVersion(version) : "";
156-
}

packages/utils/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,9 @@ export type KebabCase<T extends string, A extends string = ""> = T extends `${in
3636
export const kebabCase = <T extends string>(s: T): KebabCase<T> => s.replace(/([A-Z])/g, (_, c) => `-${c.toLowerCase()}`) as KebabCase<T>;
3737

3838
export const gracefulFlagName = (n: string) => n.length <= 1 ? `-${n}` : `--${n}`;
39-
export const gracefulVersion = (v: string) => v.startsWith("v") ? v : `v${v}`;
39+
export const gracefulVersion = (v: string) =>
40+
v.length === 0
41+
? v.startsWith("v")
42+
? v
43+
: `v${v}`
44+
: "";

0 commit comments

Comments
 (0)