@simbo/clirk 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +39 -14
- package/dist/clirk.d.ts +5 -3
- package/dist/clirk.js +12 -10
- package/dist/clirk.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/lib/add-flags-to-options.d.ts +4 -5
- package/dist/lib/add-flags-to-options.js +9 -20
- package/dist/lib/add-flags-to-options.js.map +1 -1
- package/dist/lib/apply-sigint-handler.d.ts +7 -0
- package/dist/lib/apply-sigint-handler.js +21 -0
- package/dist/lib/apply-sigint-handler.js.map +1 -0
- package/dist/lib/create-clirk-context.d.ts +5 -4
- package/dist/lib/create-clirk-context.js +37 -81
- package/dist/lib/create-clirk-context.js.map +1 -1
- package/dist/lib/generate-help-message.d.ts +1 -1
- package/dist/lib/generate-help-message.js +3 -3
- package/dist/lib/generate-help-message.js.map +1 -1
- package/dist/lib/generate-version-message.d.ts +1 -1
- package/dist/schemas/minimist-options-schema.d.ts +8 -0
- package/dist/schemas/minimist-options-schema.js +14 -0
- package/dist/schemas/minimist-options-schema.js.map +1 -0
- package/dist/schemas/options-defaults.d.ts +12 -0
- package/dist/schemas/options-defaults.js +18 -0
- package/dist/schemas/options-defaults.js.map +1 -0
- package/dist/schemas/options-schema.d.ts +25 -0
- package/dist/schemas/options-schema.js +34 -0
- package/dist/schemas/options-schema.js.map +1 -0
- package/dist/schemas/utils.d.ts +14 -0
- package/dist/schemas/utils.js +19 -0
- package/dist/schemas/utils.js.map +1 -0
- package/dist/schemas/validate-options.d.ts +29 -0
- package/dist/schemas/validate-options.js +11 -0
- package/dist/schemas/validate-options.js.map +1 -0
- package/dist/types/clirk-context.interface.d.ts +132 -0
- package/dist/types/clirk-context.interface.js +2 -0
- package/dist/types/clirk-context.interface.js.map +1 -0
- package/dist/types/clirk-options.interface.d.ts +95 -0
- package/dist/types/clirk-options.interface.js +2 -0
- package/dist/types/clirk-options.interface.js.map +1 -0
- package/dist/types/minimist-options.interface.d.ts +10 -0
- package/dist/types/minimist-options.interface.js +2 -0
- package/dist/types/minimist-options.interface.js.map +1 -0
- package/package.json +14 -12
- package/dist/clirk.types.d.ts +0 -222
- package/dist/clirk.types.js +0 -2
- package/dist/clirk.types.js.map +0 -1
- package/dist/lib/is-flag-defined.d.ts +0 -13
- package/dist/lib/is-flag-defined.js +0 -17
- package/dist/lib/is-flag-defined.js.map +0 -1
- package/dist/lib/parse-string-input.d.ts +0 -11
- package/dist/lib/parse-string-input.js +0 -18
- package/dist/lib/parse-string-input.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ClirkContext } from '../types/clirk-context.interface.js';
|
|
2
|
+
export declare const DEFAULT_MINIMIST_OPTIONS: {
|
|
3
|
+
string: never[];
|
|
4
|
+
boolean: never[];
|
|
5
|
+
alias: {};
|
|
6
|
+
default: {};
|
|
7
|
+
};
|
|
8
|
+
export declare const DEFAULT_USAGE_LABEL = "USAGE";
|
|
9
|
+
export declare const DEFAULT_PARAMETERS_LABEL = "PARAMETERS";
|
|
10
|
+
export declare const DEFAULT_OPTIONS_LABEL = "OPTIONS";
|
|
11
|
+
export declare const DEFAULT_SIGINT_MESSAGE: string;
|
|
12
|
+
export declare const DEFAULT_SIGINT_HANDLER: (context: ClirkContext) => Promise<void>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { log } from 'node:console';
|
|
2
|
+
import { terminated } from '@simbo/cli-output';
|
|
3
|
+
import { gracefulExit } from '@simbo/graceful-exit';
|
|
4
|
+
export const DEFAULT_MINIMIST_OPTIONS = {
|
|
5
|
+
string: [],
|
|
6
|
+
boolean: [],
|
|
7
|
+
alias: {},
|
|
8
|
+
default: {},
|
|
9
|
+
};
|
|
10
|
+
export const DEFAULT_USAGE_LABEL = 'USAGE';
|
|
11
|
+
export const DEFAULT_PARAMETERS_LABEL = 'PARAMETERS';
|
|
12
|
+
export const DEFAULT_OPTIONS_LABEL = 'OPTIONS';
|
|
13
|
+
export const DEFAULT_SIGINT_MESSAGE = terminated('Received SIGINT');
|
|
14
|
+
export const DEFAULT_SIGINT_HANDLER = async (context) => {
|
|
15
|
+
log(context.sigintMessage);
|
|
16
|
+
await gracefulExit(undefined, 1);
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=options-defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options-defaults.js","sourceRoot":"","sources":["../../src/schemas/options-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIpD,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,MAAM,EAAE,EAAE;IACV,OAAO,EAAE,EAAE;IACX,KAAK,EAAE,EAAE;IACT,OAAO,EAAE,EAAE;CACZ,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,OAAO,CAAC;AAC3C,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAY,CAAC;AACrD,MAAM,CAAC,MAAM,qBAAqB,GAAG,SAAS,CAAC;AAE/C,MAAM,CAAC,MAAM,sBAAsB,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC;AAEpE,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAAE,OAAqB,EAAiB,EAAE;IACnF,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC3B,MAAM,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;AACnC,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { SigIntHandler } from '../types/clirk-context.interface.js';
|
|
3
|
+
export declare const optionsSchema: z.ZodObject<{
|
|
4
|
+
importMetaDirname: z.ZodString;
|
|
5
|
+
argsOptions: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
6
|
+
string: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>, z.ZodTransform<string[], string | string[]>>>>;
|
|
7
|
+
boolean: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>, z.ZodTransform<string[], string | string[]>>>>;
|
|
8
|
+
alias: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>, z.ZodTransform<Record<string, string[]>, Record<string, string | string[]>>>>>;
|
|
9
|
+
default: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
10
|
+
}, z.core.$strict>>>;
|
|
11
|
+
title: z.ZodString;
|
|
12
|
+
name: z.ZodOptional<z.ZodString>;
|
|
13
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
14
|
+
description: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>, z.ZodTransform<string[], string | string[]>>>>;
|
|
15
|
+
examples: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>, z.ZodTransform<string[], string | string[]>>>>;
|
|
16
|
+
usage: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>, z.ZodTransform<string[], string | string[]>>>>;
|
|
17
|
+
usageLabel: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
18
|
+
parameters: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>, z.ZodTransform<Record<string, string[]>, Record<string, string | string[]>>>>>;
|
|
19
|
+
parametersLabel: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
20
|
+
options: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>, z.ZodTransform<Record<string, string[]>, Record<string, string | string[]>>>>>;
|
|
21
|
+
optionsLabel: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
22
|
+
sigintHandler: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodType<SigIntHandler, SigIntHandler, z.core.$ZodTypeInternals<SigIntHandler, SigIntHandler>>, z.ZodLiteral<false>]>>>;
|
|
23
|
+
sigintMessage: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
24
|
+
}, z.core.$strict>;
|
|
25
|
+
export type ParsedOptions = z.output<typeof optionsSchema>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createFunctionSchema, nonEmptyStringOrArrayOfStringsSchema, nonEmptyStringSchema } from '@simbo/zodpak';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { minimistOptionsSchema } from './minimist-options-schema.js';
|
|
4
|
+
import { DEFAULT_MINIMIST_OPTIONS, DEFAULT_OPTIONS_LABEL, DEFAULT_PARAMETERS_LABEL, DEFAULT_SIGINT_HANDLER, DEFAULT_SIGINT_MESSAGE, DEFAULT_USAGE_LABEL, } from './options-defaults.js';
|
|
5
|
+
import { arrayifyString, arrayifyStringRecords } from './utils.js';
|
|
6
|
+
export const optionsSchema = z.strictObject({
|
|
7
|
+
importMetaDirname: nonEmptyStringSchema,
|
|
8
|
+
argsOptions: minimistOptionsSchema.optional().default(DEFAULT_MINIMIST_OPTIONS),
|
|
9
|
+
title: nonEmptyStringSchema,
|
|
10
|
+
name: nonEmptyStringSchema.optional(),
|
|
11
|
+
icon: nonEmptyStringSchema.optional(),
|
|
12
|
+
description: nonEmptyStringOrArrayOfStringsSchema.transform(arrayifyString).optional().default([]),
|
|
13
|
+
examples: nonEmptyStringOrArrayOfStringsSchema.transform(arrayifyString).optional().default([]),
|
|
14
|
+
usage: nonEmptyStringOrArrayOfStringsSchema.transform(arrayifyString).optional().default([]),
|
|
15
|
+
usageLabel: nonEmptyStringSchema.optional().default(DEFAULT_USAGE_LABEL),
|
|
16
|
+
parameters: z
|
|
17
|
+
.record(nonEmptyStringSchema, nonEmptyStringOrArrayOfStringsSchema)
|
|
18
|
+
.transform(arrayifyStringRecords)
|
|
19
|
+
.optional()
|
|
20
|
+
.default({}),
|
|
21
|
+
parametersLabel: nonEmptyStringSchema.optional().default(DEFAULT_PARAMETERS_LABEL),
|
|
22
|
+
options: z
|
|
23
|
+
.record(nonEmptyStringSchema, nonEmptyStringOrArrayOfStringsSchema)
|
|
24
|
+
.transform(arrayifyStringRecords)
|
|
25
|
+
.optional()
|
|
26
|
+
.default({}),
|
|
27
|
+
optionsLabel: nonEmptyStringSchema.optional().default(DEFAULT_OPTIONS_LABEL),
|
|
28
|
+
sigintHandler: z
|
|
29
|
+
.union([createFunctionSchema(), z.literal(false)])
|
|
30
|
+
.optional()
|
|
31
|
+
.default(() => DEFAULT_SIGINT_HANDLER),
|
|
32
|
+
sigintMessage: nonEmptyStringSchema.optional().default(DEFAULT_SIGINT_MESSAGE),
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=options-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options-schema.js","sourceRoot":"","sources":["../../src/schemas/options-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,oCAAoC,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACjH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,YAAY,CAAC;IAC1C,iBAAiB,EAAE,oBAAoB;IACvC,WAAW,EAAE,qBAAqB,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,wBAAwB,CAAC;IAC/E,KAAK,EAAE,oBAAoB;IAC3B,IAAI,EAAE,oBAAoB,CAAC,QAAQ,EAAE;IACrC,IAAI,EAAE,oBAAoB,CAAC,QAAQ,EAAE;IACrC,WAAW,EAAE,oCAAoC,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;IAClG,QAAQ,EAAE,oCAAoC,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;IAC/F,KAAK,EAAE,oCAAoC,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;IAC5F,UAAU,EAAE,oBAAoB,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC;IACxE,UAAU,EAAE,CAAC;SACV,MAAM,CAAC,oBAAoB,EAAE,oCAAoC,CAAC;SAClE,SAAS,CAAC,qBAAqB,CAAC;SAChC,QAAQ,EAAE;SACV,OAAO,CAAC,EAAE,CAAC;IACd,eAAe,EAAE,oBAAoB,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,wBAAwB,CAAC;IAClF,OAAO,EAAE,CAAC;SACP,MAAM,CAAC,oBAAoB,EAAE,oCAAoC,CAAC;SAClE,SAAS,CAAC,qBAAqB,CAAC;SAChC,QAAQ,EAAE;SACV,OAAO,CAAC,EAAE,CAAC;IACd,YAAY,EAAE,oBAAoB,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,qBAAqB,CAAC;IAC5E,aAAa,EAAE,CAAC;SACb,KAAK,CAAC,CAAC,oBAAoB,EAAiB,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;SAChE,QAAQ,EAAE;SACV,OAAO,CAAC,GAAG,EAAE,CAAC,sBAAsB,CAAC;IACxC,aAAa,EAAE,oBAAoB,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,sBAAsB,CAAC;CAC/E,CAA4C,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string or an array of strings to an array of strings.
|
|
3
|
+
*
|
|
4
|
+
* @param value - The input value to transform.
|
|
5
|
+
* @returns An array of strings.
|
|
6
|
+
*/
|
|
7
|
+
export declare function arrayifyString(value: string | string[]): string[];
|
|
8
|
+
/**
|
|
9
|
+
* Converts a record of string or string arrays to a record of string arrays.
|
|
10
|
+
*
|
|
11
|
+
* @param obj - The input object to transform.
|
|
12
|
+
* @returns A new object with all string values converted to arrays of strings.
|
|
13
|
+
*/
|
|
14
|
+
export declare function arrayifyStringRecords(obj: Record<string, string | string[]>): Record<string, string[]>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string or an array of strings to an array of strings.
|
|
3
|
+
*
|
|
4
|
+
* @param value - The input value to transform.
|
|
5
|
+
* @returns An array of strings.
|
|
6
|
+
*/
|
|
7
|
+
export function arrayifyString(value) {
|
|
8
|
+
return typeof value === 'string' ? [value] : value;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Converts a record of string or string arrays to a record of string arrays.
|
|
12
|
+
*
|
|
13
|
+
* @param obj - The input object to transform.
|
|
14
|
+
* @returns A new object with all string values converted to arrays of strings.
|
|
15
|
+
*/
|
|
16
|
+
export function arrayifyStringRecords(obj) {
|
|
17
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, arrayifyString(v)]));
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/schemas/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAwB;IACrD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACrD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAsC;IAC1E,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACzF,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates the options for the CLI.
|
|
3
|
+
*
|
|
4
|
+
* @param input - The options to validate.
|
|
5
|
+
* @returns The validated options.
|
|
6
|
+
* @throws {ValidationError} If the options are invalid.
|
|
7
|
+
*/
|
|
8
|
+
export declare const validateOptions: (input: unknown) => {
|
|
9
|
+
importMetaDirname: string;
|
|
10
|
+
argsOptions: {
|
|
11
|
+
string: string[];
|
|
12
|
+
boolean: string[];
|
|
13
|
+
alias: Record<string, string[]>;
|
|
14
|
+
default: Record<string, any>;
|
|
15
|
+
};
|
|
16
|
+
title: string;
|
|
17
|
+
description: string[];
|
|
18
|
+
examples: string[];
|
|
19
|
+
usage: string[];
|
|
20
|
+
usageLabel: string;
|
|
21
|
+
parameters: Record<string, string[]>;
|
|
22
|
+
parametersLabel: string;
|
|
23
|
+
options: Record<string, string[]>;
|
|
24
|
+
optionsLabel: string;
|
|
25
|
+
sigintHandler: false | import("../index.js").SigIntHandler;
|
|
26
|
+
sigintMessage: string;
|
|
27
|
+
name?: string | undefined;
|
|
28
|
+
icon?: string | undefined;
|
|
29
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createValidationFunction } from '@simbo/zodpak';
|
|
2
|
+
import { optionsSchema } from './options-schema.js';
|
|
3
|
+
/**
|
|
4
|
+
* Validates the options for the CLI.
|
|
5
|
+
*
|
|
6
|
+
* @param input - The options to validate.
|
|
7
|
+
* @returns The validated options.
|
|
8
|
+
* @throws {ValidationError} If the options are invalid.
|
|
9
|
+
*/
|
|
10
|
+
export const validateOptions = createValidationFunction(optionsSchema);
|
|
11
|
+
//# sourceMappingURL=validate-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-options.js","sourceRoot":"","sources":["../../src/schemas/validate-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,wBAAwB,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { PackageNormalized } from '@simbo/find-up-package';
|
|
2
|
+
import type { ParsedArgs } from 'minimist';
|
|
3
|
+
import type { ParsedMinimistOptions } from '../schemas/minimist-options-schema.js';
|
|
4
|
+
/**
|
|
5
|
+
* The context for the clirk CLI.
|
|
6
|
+
*/
|
|
7
|
+
export interface ClirkContext {
|
|
8
|
+
/**
|
|
9
|
+
* The absolute path to the directory containing the CLI's package.json.
|
|
10
|
+
*/
|
|
11
|
+
importPath: string;
|
|
12
|
+
/**
|
|
13
|
+
* The parsed options that were passed to minimist.
|
|
14
|
+
*/
|
|
15
|
+
argsOptions: ParsedMinimistOptions;
|
|
16
|
+
/**
|
|
17
|
+
* The parsed command line arguments from minimist.
|
|
18
|
+
*/
|
|
19
|
+
args: ParsedArgs;
|
|
20
|
+
/**
|
|
21
|
+
* The printable title of the CLI.
|
|
22
|
+
*/
|
|
23
|
+
title: string;
|
|
24
|
+
/**
|
|
25
|
+
* The command name of the CLI.
|
|
26
|
+
*/
|
|
27
|
+
name: string;
|
|
28
|
+
/**
|
|
29
|
+
* An optional icon for the CLI.
|
|
30
|
+
*/
|
|
31
|
+
icon?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The package information of the CLI.
|
|
34
|
+
* This is derived from the package.json file in the CLI's directory.
|
|
35
|
+
*/
|
|
36
|
+
package: PackageNormalized;
|
|
37
|
+
/**
|
|
38
|
+
* The actual command name extracted from `process.argv`.
|
|
39
|
+
*/
|
|
40
|
+
commandName: string;
|
|
41
|
+
/**
|
|
42
|
+
* The description of the CLI.
|
|
43
|
+
*/
|
|
44
|
+
description: string[];
|
|
45
|
+
/**
|
|
46
|
+
* Usage examples for the CLI.
|
|
47
|
+
*/
|
|
48
|
+
examples: string[];
|
|
49
|
+
/**
|
|
50
|
+
* Usage instructions for the CLI.
|
|
51
|
+
*/
|
|
52
|
+
usage: string[];
|
|
53
|
+
/**
|
|
54
|
+
* A label for the usage section.
|
|
55
|
+
* This is used in the help message to indicate the usage section.
|
|
56
|
+
*/
|
|
57
|
+
usageLabel: string;
|
|
58
|
+
/**
|
|
59
|
+
* The parameters for the CLI.
|
|
60
|
+
* This is a map of parameter names to their descriptions.
|
|
61
|
+
*/
|
|
62
|
+
parameters: Map<string, CliParameter>;
|
|
63
|
+
/**
|
|
64
|
+
* A label for the parameters section.
|
|
65
|
+
* This is used in the help message to indicate the parameters section.
|
|
66
|
+
*/
|
|
67
|
+
parametersLabel: string;
|
|
68
|
+
/**
|
|
69
|
+
* The options for the CLI.
|
|
70
|
+
* This is a map of option names to their descriptions and properties.
|
|
71
|
+
*/
|
|
72
|
+
options: Map<string, CliOption>;
|
|
73
|
+
/**
|
|
74
|
+
* A label for the options section.
|
|
75
|
+
* This is used in the help message to indicate the options section.
|
|
76
|
+
*/
|
|
77
|
+
optionsLabel: string;
|
|
78
|
+
/**
|
|
79
|
+
* The function to handle the SIGINT signal (Ctrl+C).
|
|
80
|
+
* If undefined, clirk will not handle the SIGINT signal.
|
|
81
|
+
*/
|
|
82
|
+
sigintHandler: SigIntHandler | false;
|
|
83
|
+
/**
|
|
84
|
+
* The message to display when the SIGINT signal (CTRL+C) is received.
|
|
85
|
+
* This is either a custom message provided by the user or a default message.
|
|
86
|
+
*/
|
|
87
|
+
sigintMessage: string;
|
|
88
|
+
/**
|
|
89
|
+
* Generates a help message for the CLI.
|
|
90
|
+
* This includes the title, description, usage, examples, parameters, and options.
|
|
91
|
+
*/
|
|
92
|
+
getHelpMessage: () => string;
|
|
93
|
+
/**
|
|
94
|
+
* Generates a version message for the CLI.
|
|
95
|
+
* This includes the package name and version.
|
|
96
|
+
*/
|
|
97
|
+
getVersionMessage: () => string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The Clirk context before handlers for help and version messages are added.
|
|
101
|
+
*/
|
|
102
|
+
export type ClirkContextWithoutMessages = Omit<ClirkContext, 'getHelpMessage' | 'getVersionMessage'>;
|
|
103
|
+
/**
|
|
104
|
+
* A parameter for the CLI.
|
|
105
|
+
*/
|
|
106
|
+
export interface CliParameter {
|
|
107
|
+
/**
|
|
108
|
+
* The description of the parameter.
|
|
109
|
+
*/
|
|
110
|
+
description: string[];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* An option of the CLI.
|
|
114
|
+
*/
|
|
115
|
+
export interface CliOption {
|
|
116
|
+
/**
|
|
117
|
+
* The description of the option.
|
|
118
|
+
*/
|
|
119
|
+
description: string[];
|
|
120
|
+
/**
|
|
121
|
+
* The aliases for the option.
|
|
122
|
+
*/
|
|
123
|
+
aliases: Set<string>;
|
|
124
|
+
/**
|
|
125
|
+
* Whether the option is a boolean or a string flag.
|
|
126
|
+
*/
|
|
127
|
+
type: 'boolean' | 'string';
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* A function to handle the SIGINT signal (Ctrl+C).
|
|
131
|
+
*/
|
|
132
|
+
export type SigIntHandler = (context: ClirkContext) => void | Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clirk-context.interface.js","sourceRoot":"","sources":["../../src/types/clirk-context.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { SigIntHandler } from './clirk-context.interface.js';
|
|
2
|
+
import type { MinimistOptions } from './minimist-options.interface.js';
|
|
3
|
+
/**
|
|
4
|
+
* The options for clirk.
|
|
5
|
+
*/
|
|
6
|
+
export interface ClirkOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The `import.meta.dirname` from any script within the CLI package.
|
|
9
|
+
* This is used to resolve the CLI package information.
|
|
10
|
+
*/
|
|
11
|
+
importMetaDirname: string;
|
|
12
|
+
/**
|
|
13
|
+
* The options for parsing command line arguments.
|
|
14
|
+
* This is passed to the minimist library.
|
|
15
|
+
* If these options do not include `--help` or `--version`, clirk will take
|
|
16
|
+
* care of this and also take over if the flags are present.
|
|
17
|
+
*/
|
|
18
|
+
argsOptions?: MinimistOptions;
|
|
19
|
+
/**
|
|
20
|
+
* The printable title of the CLI.
|
|
21
|
+
*/
|
|
22
|
+
title: string;
|
|
23
|
+
/**
|
|
24
|
+
* The command name to run the CLI.
|
|
25
|
+
*/
|
|
26
|
+
name?: string;
|
|
27
|
+
/**
|
|
28
|
+
* An optional icon for the CLI.
|
|
29
|
+
* This will be displayed in the help message.
|
|
30
|
+
*/
|
|
31
|
+
icon?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The description of the CLI.
|
|
34
|
+
* If not provided, it will be derived from the CLI's package.json.
|
|
35
|
+
* Use an array of strings for multiple lines to support indentation.
|
|
36
|
+
*/
|
|
37
|
+
description?: string | string[];
|
|
38
|
+
/**
|
|
39
|
+
* Usage examples for the CLI.
|
|
40
|
+
* Use an array of strings for multiple lines to support indentation.
|
|
41
|
+
* Defaults to the command name.
|
|
42
|
+
*/
|
|
43
|
+
examples?: string | string[];
|
|
44
|
+
/**
|
|
45
|
+
* Usage instructions for the CLI. Optional, but recommended.
|
|
46
|
+
* Use an array of strings for multiple lines to support indentation.
|
|
47
|
+
*/
|
|
48
|
+
usage?: string | string[];
|
|
49
|
+
/**
|
|
50
|
+
* A label for the usage section.
|
|
51
|
+
* If not provided, it will default to "USAGE".
|
|
52
|
+
* This is used in the help message to indicate the usage section.
|
|
53
|
+
*/
|
|
54
|
+
usageLabel?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Parameters for the CLI. (Arguments that are not options.)
|
|
57
|
+
* This defines the supported parameters for the CLI for help messages.
|
|
58
|
+
* The keys are the names of the parameters, and the values are their descriptions.
|
|
59
|
+
* Use an array of strings for multiple lines to support indentation.
|
|
60
|
+
*/
|
|
61
|
+
parameters?: Record<string, string | string[]>;
|
|
62
|
+
/**
|
|
63
|
+
* A label for the parameters section.
|
|
64
|
+
* If not provided, it will default to "PARAMETERS".
|
|
65
|
+
* This is used in the help message to indicate the parameters section.
|
|
66
|
+
*/
|
|
67
|
+
parametersLabel?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Options for the CLI.
|
|
70
|
+
* This defines the supported options for the CLI for help messages.
|
|
71
|
+
* The keys are the names of the options, and the values are their descriptions.
|
|
72
|
+
* Use an array of strings for multiple lines to support indentation.
|
|
73
|
+
*/
|
|
74
|
+
options?: Record<string, string | string[]>;
|
|
75
|
+
/**
|
|
76
|
+
* A label for the options section.
|
|
77
|
+
* If not provided, it will default to "OPTIONS".
|
|
78
|
+
* This is used in the help message to indicate the options section.
|
|
79
|
+
*/
|
|
80
|
+
optionsLabel?: string;
|
|
81
|
+
/**
|
|
82
|
+
* A function to handle the SIGINT signal (Ctrl+C).
|
|
83
|
+
* If provided, this function will be called when the user presses Ctrl+C.
|
|
84
|
+
* If not provided, clirk will handle the SIGINT signal and exit gracefully.
|
|
85
|
+
* The default message can be customized using the `sigintMessage` option.
|
|
86
|
+
* If set to `false`, clirk will not handle the SIGINT signal.
|
|
87
|
+
*/
|
|
88
|
+
sigintHandler?: SigIntHandler | false;
|
|
89
|
+
/**
|
|
90
|
+
* The message to display when the SIGINT signal (CTRL+C) is received.
|
|
91
|
+
* If not provided, a default message will be used.
|
|
92
|
+
* This option is only used if `sigintHandler` is not set to `false`.
|
|
93
|
+
*/
|
|
94
|
+
sigintMessage?: string;
|
|
95
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clirk-options.interface.js","sourceRoot":"","sources":["../../src/types/clirk-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Opts } from 'minimist';
|
|
2
|
+
/**
|
|
3
|
+
* Minimist Options for Clirk
|
|
4
|
+
*
|
|
5
|
+
* Clirk supports all minimist options except `boolean: true` which is IMHO
|
|
6
|
+
* just unnecessary complexity without benefit.
|
|
7
|
+
*/
|
|
8
|
+
export interface MinimistOptions extends Opts {
|
|
9
|
+
boolean?: string | string[];
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minimist-options.interface.js","sourceRoot":"","sources":["../../src/types/minimist-options.interface.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simbo/clirk",
|
|
3
|
-
"description": "A utility
|
|
4
|
-
"version": "1.
|
|
3
|
+
"description": "A utility that makes creating Node.js CLIs easier by providing common functionality out of the box, with excellent performance and a minimal footprint.",
|
|
4
|
+
"version": "1.1.1",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
7
7
|
"framework",
|
|
@@ -41,16 +41,18 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"minimist": "^1.2.8",
|
|
43
43
|
"yoctocolors": "^2.1.1",
|
|
44
|
-
"
|
|
45
|
-
"@simbo/
|
|
46
|
-
"@simbo/
|
|
47
|
-
"@simbo/graceful-exit": "1.0
|
|
48
|
-
"@simbo/
|
|
44
|
+
"zod": "^4.1.5",
|
|
45
|
+
"@simbo/cli-output": "1.0.1",
|
|
46
|
+
"@simbo/find-up-package": "1.0.2",
|
|
47
|
+
"@simbo/graceful-exit": "1.1.0",
|
|
48
|
+
"@simbo/zodpak": "0.1.1",
|
|
49
|
+
"@simbo/stringify-error": "1.0.2",
|
|
50
|
+
"@simbo/plural": "1.0.1"
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
|
-
"@ianvs/prettier-plugin-sort-imports": "^4.
|
|
52
|
-
"@types/node": "^20.19.11",
|
|
53
|
+
"@ianvs/prettier-plugin-sort-imports": "^4.7.0",
|
|
53
54
|
"@types/minimist": "^1.2.5",
|
|
55
|
+
"@types/node": "^20.19.11",
|
|
54
56
|
"@vitest/coverage-v8": "^3.2.4",
|
|
55
57
|
"@vitest/ui": "^3.2.4",
|
|
56
58
|
"eslint": "^9.34.0",
|
|
@@ -59,9 +61,9 @@
|
|
|
59
61
|
"prettier-plugin-organize-attributes": "^1.0.0",
|
|
60
62
|
"typescript": "^5.9.2",
|
|
61
63
|
"vitest": "^3.2.4",
|
|
62
|
-
"@simbo/eslint-config": "1.0.
|
|
63
|
-
"@simbo/
|
|
64
|
-
"@simbo/
|
|
64
|
+
"@simbo/eslint-config": "1.0.4",
|
|
65
|
+
"@simbo/tsconfig": "1.0.4",
|
|
66
|
+
"@simbo/prettier-config": "1.0.4"
|
|
65
67
|
},
|
|
66
68
|
"scripts": {
|
|
67
69
|
"build": "tsc --project tsconfig.build.json",
|