-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathversion.ts
51 lines (47 loc) · 1.31 KB
/
version.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// deno-lint-ignore-file no-explicit-any
import { BaseContext, CommandConfig } from "./command.ts";
import { CommandFactory } from "./init.ts";
import * as intl from "./intl.ts";
export function version<
Context extends {
meta: { version: string; date?: string; commit?: string };
},
>(commandFactory: CommandFactory<Context, any>, options:
& {
/**
* Change the name of the command
* @default "version"
*/
name?: string;
}
& Pick<
CommandConfig<Context & BaseContext, any, any>,
"aliases" | "short" | "long" | "use" | "hidden"
> = {}) {
const { name = "version", ...config } = options;
return commandFactory.command(name, {
short: "Show version information",
long:
"Shows version information command, including version number and build date.",
...config,
})
.run(function* ({ ctx: { meta, path } }) {
const bin = path[0];
const metaStr = [
meta.date &&
`build date: ${
intl.date(
new Date(meta.date),
{
dateStyle: "medium",
timeStyle: "short",
},
)
}`,
meta.commit && `commit: ${meta.commit}`,
].filter(Boolean).join("; ");
yield `${bin} v${meta.version}${
metaStr.length > 1 ? ` (${metaStr})` : ""
}`;
});
}