-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli-messages.ts
More file actions
34 lines (31 loc) · 1.53 KB
/
cli-messages.ts
File metadata and controls
34 lines (31 loc) · 1.53 KB
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
import Cli from ".";
export const CLI_MESSAGES = {
"execute.base-location-error": "There was a problem finding base script location",
"execute.handler-not-found": "Could not find handler for command in {path}",
"execute.execution-error": "There was a problem executing the script ({path}: {error})",
"generate-help.scope-not-found": "Unable to find the specified scope ({scope})",
"generate-help.usage": "Usage",
"generate-help.has-options": "[OPTIONS]",
"generate-help.option-default": "default: {default}",
"generate-help.option-enum": "allowed: {enum}",
"generate-help.namespaces-title": "Namespaces",
"generate-help.commands-title": "Commands",
"generate-help.options-title": "Options",
"generate-version.template": " {cliName} version: {cliVersion}\n",
"parse-arguments.suggestion": '. Did you mean "{suggestion}" ?',
"help.description": "Display global help, or scoped to a namespace/command",
"version.description": "Display version",
} as const;
type ExtractVariables<T> = T extends `${string}{${infer Var}}${infer Rest}` ? Var | ExtractVariables<Rest> : never;
/** Method for formatting internationalized messages */
export function formatMessage<T extends keyof typeof Cli.messages>(
messageId: T,
...params: ExtractVariables<(typeof Cli.messages)[T]> extends never
? []
: [{ [key in ExtractVariables<(typeof Cli.messages)[T]>]: string }]
) {
return Object.entries(params[0] || {}).reduce(
(acc, [k, v]) => acc.replace(new RegExp(`{${k}}`, "g"), v as string),
(Cli.messages as any)[messageId],
);
}