@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
package/dist/clirk.types.d.ts
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
import type { PackageNormalized } from '@simbo/find-up-package';
|
|
2
|
-
import type { Opts, ParsedArgs } from 'minimist';
|
|
3
|
-
/**
|
|
4
|
-
* The options for clirk.
|
|
5
|
-
*/
|
|
6
|
-
export interface ClirkOptions {
|
|
7
|
-
/**
|
|
8
|
-
* The `import.meta` from any script within the CLI package.
|
|
9
|
-
* This is used to resolve the CLI package information.
|
|
10
|
-
*/
|
|
11
|
-
importMeta: 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?: Opts;
|
|
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?: (() => void) | 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
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* The context for the clirk CLI.
|
|
98
|
-
*/
|
|
99
|
-
export interface ClirkContext {
|
|
100
|
-
/**
|
|
101
|
-
* The options for parsing command line arguments.
|
|
102
|
-
* This is passed to the minimist library.
|
|
103
|
-
*/
|
|
104
|
-
argsOptions: Opts;
|
|
105
|
-
/**
|
|
106
|
-
* The parsed command line arguments.
|
|
107
|
-
* This is the result of calling minimist with the provided argsOptions.
|
|
108
|
-
*/
|
|
109
|
-
args: ParsedArgs;
|
|
110
|
-
/**
|
|
111
|
-
* The printable title of the CLI.
|
|
112
|
-
*/
|
|
113
|
-
title: string;
|
|
114
|
-
/**
|
|
115
|
-
* The command name of the CLI.
|
|
116
|
-
*/
|
|
117
|
-
name: string;
|
|
118
|
-
/**
|
|
119
|
-
* An optional icon for the CLI.
|
|
120
|
-
*/
|
|
121
|
-
icon?: string;
|
|
122
|
-
/**
|
|
123
|
-
* The package information of the CLI.
|
|
124
|
-
* This is derived from the package.json file in the CLI's directory.
|
|
125
|
-
*/
|
|
126
|
-
package: PackageNormalized;
|
|
127
|
-
/**
|
|
128
|
-
* The actual command name extracted from `process.argv`.
|
|
129
|
-
*/
|
|
130
|
-
commandName: string;
|
|
131
|
-
/**
|
|
132
|
-
* The description of the CLI.
|
|
133
|
-
*/
|
|
134
|
-
description: string[];
|
|
135
|
-
/**
|
|
136
|
-
* Usage examples for the CLI.
|
|
137
|
-
*/
|
|
138
|
-
examples: string[];
|
|
139
|
-
/**
|
|
140
|
-
* Usage instructions for the CLI.
|
|
141
|
-
*/
|
|
142
|
-
usage: string[];
|
|
143
|
-
/**
|
|
144
|
-
* A label for the usage section.
|
|
145
|
-
* This is used in the help message to indicate the usage section.
|
|
146
|
-
*/
|
|
147
|
-
usageLabel: string;
|
|
148
|
-
/**
|
|
149
|
-
* The parameters for the CLI.
|
|
150
|
-
* This is a map of parameter names to their descriptions.
|
|
151
|
-
*/
|
|
152
|
-
parameters: Map<string, CliParameter>;
|
|
153
|
-
/**
|
|
154
|
-
* A label for the parameters section.
|
|
155
|
-
* This is used in the help message to indicate the parameters section.
|
|
156
|
-
*/
|
|
157
|
-
parametersLabel: string;
|
|
158
|
-
/**
|
|
159
|
-
* The options for the CLI.
|
|
160
|
-
* This is a map of option names to their descriptions and properties.
|
|
161
|
-
*/
|
|
162
|
-
options: Map<string, CliOption>;
|
|
163
|
-
/**
|
|
164
|
-
* A label for the options section.
|
|
165
|
-
* This is used in the help message to indicate the options section.
|
|
166
|
-
*/
|
|
167
|
-
optionsLabel: string;
|
|
168
|
-
/**
|
|
169
|
-
* The function to handle the SIGINT signal (Ctrl+C).
|
|
170
|
-
* If undefined, clirk will not handle the SIGINT signal.
|
|
171
|
-
*/
|
|
172
|
-
sigintHandler?: () => void;
|
|
173
|
-
/**
|
|
174
|
-
* The message to display when the SIGINT signal (CTRL+C) is received.
|
|
175
|
-
* This is either a custom message provided by the user or a default message.
|
|
176
|
-
*/
|
|
177
|
-
sigintMessage: string;
|
|
178
|
-
/**
|
|
179
|
-
* Generates a help message for the CLI.
|
|
180
|
-
* This includes the title, description, usage, examples, parameters, and options.
|
|
181
|
-
*/
|
|
182
|
-
getHelpMessage: () => string;
|
|
183
|
-
/**
|
|
184
|
-
* Generates a version message for the CLI.
|
|
185
|
-
* This includes the package name and version.
|
|
186
|
-
*/
|
|
187
|
-
getVersionMessage: () => string;
|
|
188
|
-
}
|
|
189
|
-
export type ClirkContextWithoutMessages = Omit<ClirkContext, 'getHelpMessage' | 'getVersionMessage'>;
|
|
190
|
-
/**
|
|
191
|
-
* A parameter argument for the CLI.
|
|
192
|
-
*/
|
|
193
|
-
export interface CliParameter {
|
|
194
|
-
/**
|
|
195
|
-
* The description of the parameter argument.
|
|
196
|
-
*/
|
|
197
|
-
description: string[];
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* An option for the CLI.
|
|
201
|
-
*/
|
|
202
|
-
export interface CliOption {
|
|
203
|
-
/**
|
|
204
|
-
* The description of the option.
|
|
205
|
-
*/
|
|
206
|
-
description: string[];
|
|
207
|
-
/**
|
|
208
|
-
* The aliases for the option.
|
|
209
|
-
* This is a set of strings that can be used as alternative names for the option.
|
|
210
|
-
*/
|
|
211
|
-
aliases: Set<string>;
|
|
212
|
-
/**
|
|
213
|
-
* Whether the option is a boolean flag.
|
|
214
|
-
* If true, the option does not require a value and is either present or absent.
|
|
215
|
-
*/
|
|
216
|
-
isBoolean: boolean;
|
|
217
|
-
/**
|
|
218
|
-
* Whether the option is a string value.
|
|
219
|
-
* If true, the option requires a string value.
|
|
220
|
-
*/
|
|
221
|
-
isString: boolean;
|
|
222
|
-
}
|
package/dist/clirk.types.js
DELETED
package/dist/clirk.types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clirk.types.js","sourceRoot":"","sources":["../src/clirk.types.ts"],"names":[],"mappings":""}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Opts } from 'minimist';
|
|
2
|
-
/**
|
|
3
|
-
* Checks if a flag is defined in the provided minimist options.
|
|
4
|
-
*
|
|
5
|
-
* A flag is considered defined if:
|
|
6
|
-
* - It is listed in the `boolean` array, or
|
|
7
|
-
* - It is listed as a key in the `alias` object.
|
|
8
|
-
*
|
|
9
|
-
* @param opts - The minimist options object.
|
|
10
|
-
* @param flag - The long or short flag name to check.
|
|
11
|
-
* @returns True if the flag is defined as a boolean or has an alias, false otherwise.
|
|
12
|
-
*/
|
|
13
|
-
export declare function isFlagDefined(opts: Opts | undefined, flag: string): boolean;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if a flag is defined in the provided minimist options.
|
|
3
|
-
*
|
|
4
|
-
* A flag is considered defined if:
|
|
5
|
-
* - It is listed in the `boolean` array, or
|
|
6
|
-
* - It is listed as a key in the `alias` object.
|
|
7
|
-
*
|
|
8
|
-
* @param opts - The minimist options object.
|
|
9
|
-
* @param flag - The long or short flag name to check.
|
|
10
|
-
* @returns True if the flag is defined as a boolean or has an alias, false otherwise.
|
|
11
|
-
*/
|
|
12
|
-
export function isFlagDefined(opts, flag) {
|
|
13
|
-
if (!opts)
|
|
14
|
-
return false;
|
|
15
|
-
return (Array.isArray(opts.boolean) && opts.boolean.includes(flag)) || !!opts.alias?.[flag];
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=is-flag-defined.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-flag-defined.js","sourceRoot":"","sources":["../../src/lib/is-flag-defined.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAAC,IAAsB,EAAE,IAAY;IAChE,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC;IACxB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC;AAC9F,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parses an unknown input into an array of strings.
|
|
3
|
-
*
|
|
4
|
-
* If a single string is passed, it will be wrapped in an array.
|
|
5
|
-
* If an array is passed, only string elements will be kept.
|
|
6
|
-
* All other types result in an empty array.
|
|
7
|
-
*
|
|
8
|
-
* @param input - The input to parse.
|
|
9
|
-
* @returns An array of strings.
|
|
10
|
-
*/
|
|
11
|
-
export declare function parseStringInput(input: unknown): string[];
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parses an unknown input into an array of strings.
|
|
3
|
-
*
|
|
4
|
-
* If a single string is passed, it will be wrapped in an array.
|
|
5
|
-
* If an array is passed, only string elements will be kept.
|
|
6
|
-
* All other types result in an empty array.
|
|
7
|
-
*
|
|
8
|
-
* @param input - The input to parse.
|
|
9
|
-
* @returns An array of strings.
|
|
10
|
-
*/
|
|
11
|
-
export function parseStringInput(input) {
|
|
12
|
-
return typeof input === 'string'
|
|
13
|
-
? [input]
|
|
14
|
-
: Array.isArray(input)
|
|
15
|
-
? input.filter((item) => typeof item === 'string')
|
|
16
|
-
: [];
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=parse-string-input.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse-string-input.js","sourceRoot":"","sources":["../../src/lib/parse-string-input.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,OAAO,KAAK,KAAK,QAAQ;QAC9B,CAAC,CAAC,CAAC,KAAK,CAAC;QACT,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YACpB,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC;YAClE,CAAC,CAAC,EAAE,CAAC;AACX,CAAC"}
|