@simbo/clirk 1.0.0
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 +7 -0
- package/LICENSE.md +20 -0
- package/README.md +85 -0
- package/dist/clirk.d.ts +13 -0
- package/dist/clirk.js +48 -0
- package/dist/clirk.js.map +1 -0
- package/dist/clirk.types.d.ts +222 -0
- package/dist/clirk.types.js +2 -0
- package/dist/clirk.types.js.map +1 -0
- package/dist/clitch/clitch.d.ts +7 -0
- package/dist/clitch/clitch.js +18 -0
- package/dist/clitch/clitch.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/add-flags-to-options.d.ts +12 -0
- package/dist/lib/add-flags-to-options.js +37 -0
- package/dist/lib/add-flags-to-options.js.map +1 -0
- package/dist/lib/create-clirk-context.d.ts +15 -0
- package/dist/lib/create-clirk-context.js +133 -0
- package/dist/lib/create-clirk-context.js.map +1 -0
- package/dist/lib/generate-help-message.d.ts +9 -0
- package/dist/lib/generate-help-message.js +91 -0
- package/dist/lib/generate-help-message.js.map +1 -0
- package/dist/lib/generate-version-message.d.ts +8 -0
- package/dist/lib/generate-version-message.js +11 -0
- package/dist/lib/generate-version-message.js.map +1 -0
- package/dist/lib/is-flag-defined.d.ts +13 -0
- package/dist/lib/is-flag-defined.js +17 -0
- package/dist/lib/is-flag-defined.js.map +1 -0
- package/dist/lib/parse-string-input.d.ts +11 -0
- package/dist/lib/parse-string-input.js +18 -0
- package/dist/lib/parse-string-input.js.map +1 -0
- package/package.json +75 -0
package/CHANGELOG.md
ADDED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright Š 2025 Simon Lepel <simbo@simbo.de> (https://simbo.de)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Clirk - The CLI Clerk
|
|
2
|
+
|
|
3
|
+
[đĻ **`@simbo/clirk`**](https://npmjs.com/package/@simbo/clirk)
|
|
4
|
+
|
|
5
|
+
A utility that simplifies creating Node.js CLIs and provides **common CLI
|
|
6
|
+
functionalities** out of the box.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- âī¸ Parses command-line arguments with
|
|
11
|
+
[`minimist`](https://www.npmjs.com/package/minimist)
|
|
12
|
+
|
|
13
|
+
- âšī¸ Auto-handles `--help` and `--version` flags (unless overridden)
|
|
14
|
+
|
|
15
|
+
- đ Provides formatted help and version messages
|
|
16
|
+
|
|
17
|
+
- đ Handles `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) gracefully with
|
|
18
|
+
customizable messages
|
|
19
|
+
|
|
20
|
+
- đ Exposes structured metadata (title, description, parameters, options,
|
|
21
|
+
examples)
|
|
22
|
+
|
|
23
|
+
- đ Fully typed with TypeScript
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
Install `@simbo/clirk` from the npm registry:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm i [-D] @simbo/clirk
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
For a complete API reference, see the
|
|
36
|
+
[documentation](https://simbo.codes/packages/modules/_simbo_clirk/).
|
|
37
|
+
|
|
38
|
+
### Examples
|
|
39
|
+
|
|
40
|
+
#### Define CLI Options
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import type { ClirkOptions } from '@simbo/clirk';
|
|
44
|
+
|
|
45
|
+
export const CLI_OPTIONS: ClirkOptions = {
|
|
46
|
+
argsOptions: {
|
|
47
|
+
// minimist options for parsing command line arguments
|
|
48
|
+
},
|
|
49
|
+
name: 'my-cli',
|
|
50
|
+
title: 'My CLI Tool',
|
|
51
|
+
description: 'An awesome CLI tool.',
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### Bootstrap the CLI
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { clirk } from '@simbo/clirk';
|
|
59
|
+
import { CLI_OPTIONS } from './cli-options.js';
|
|
60
|
+
|
|
61
|
+
export async function main() {
|
|
62
|
+
const { args } = clirk(CLI_OPTIONS);
|
|
63
|
+
// Arguments are parsed.
|
|
64
|
+
// --help and --version commands are available.
|
|
65
|
+
// SIGINT handling is set up.
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### Add Error Handling
|
|
70
|
+
|
|
71
|
+
Wrap your CLI entrypoint with
|
|
72
|
+
[`clitch`](https://simbo.codes/packages/functions/_simbo_clirk.clitch.clitch/)
|
|
73
|
+
to ensure errors and exits are handled consistently:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
#!/usr/bin/env node
|
|
77
|
+
import { clitch } from '@simbo/clirk/clitch';
|
|
78
|
+
import { main } from './main.js';
|
|
79
|
+
|
|
80
|
+
await clitch(main);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
[MIT Š Simon Lepel](http://simbo.mit-license.org/2025/)
|
package/dist/clirk.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ClirkContext, ClirkOptions } from './clirk.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* clirk - The CLI clerk.
|
|
4
|
+
* This function initializes the CLI clerk with the provided options.
|
|
5
|
+
* It parses arguments, provides CLI package information and takes over common
|
|
6
|
+
* CLI tasks like generating help messages, displaying version information, and
|
|
7
|
+
* handling SIGINT.
|
|
8
|
+
*
|
|
9
|
+
* @param cliOptions - The options for clirk.
|
|
10
|
+
* @returns A promise that resolves to the ClirkContext, which contains the
|
|
11
|
+
* parsed arguments and options as well as CLI package information.
|
|
12
|
+
*/
|
|
13
|
+
export declare function clirk(cliOptions: ClirkOptions): Promise<ClirkContext>;
|
package/dist/clirk.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { log } from 'node:console';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import { gracefulExit } from '@simbo/graceful-exit';
|
|
4
|
+
import { addFlagsToOptions } from './lib/add-flags-to-options.js';
|
|
5
|
+
import { createClirkContext } from './lib/create-clirk-context.js';
|
|
6
|
+
import { generateHelpMessage } from './lib/generate-help-message.js';
|
|
7
|
+
import { generateVersionMessage } from './lib/generate-version-message.js';
|
|
8
|
+
import { isFlagDefined } from './lib/is-flag-defined.js';
|
|
9
|
+
/**
|
|
10
|
+
* clirk - The CLI clerk.
|
|
11
|
+
* This function initializes the CLI clerk with the provided options.
|
|
12
|
+
* It parses arguments, provides CLI package information and takes over common
|
|
13
|
+
* CLI tasks like generating help messages, displaying version information, and
|
|
14
|
+
* handling SIGINT.
|
|
15
|
+
*
|
|
16
|
+
* @param cliOptions - The options for clirk.
|
|
17
|
+
* @returns A promise that resolves to the ClirkContext, which contains the
|
|
18
|
+
* parsed arguments and options as well as CLI package information.
|
|
19
|
+
*/
|
|
20
|
+
export async function clirk(cliOptions) {
|
|
21
|
+
const helpHandledByUser = isFlagDefined(cliOptions.argsOptions, 'help');
|
|
22
|
+
const versionHandledByUser = isFlagDefined(cliOptions.argsOptions, 'version');
|
|
23
|
+
cliOptions = addFlagsToOptions(cliOptions, {
|
|
24
|
+
help: !helpHandledByUser,
|
|
25
|
+
version: !versionHandledByUser,
|
|
26
|
+
});
|
|
27
|
+
const partialContext = await createClirkContext(cliOptions);
|
|
28
|
+
const getHelpMessage = () => generateHelpMessage(partialContext);
|
|
29
|
+
const getVersionMessage = () => generateVersionMessage(partialContext);
|
|
30
|
+
const context = {
|
|
31
|
+
...partialContext,
|
|
32
|
+
getHelpMessage,
|
|
33
|
+
getVersionMessage,
|
|
34
|
+
};
|
|
35
|
+
if (typeof context.sigintHandler === 'function' && !process.listenerCount('SIGINT')) {
|
|
36
|
+
process.on('SIGINT', context.sigintHandler);
|
|
37
|
+
}
|
|
38
|
+
if (!helpHandledByUser && context.args.help) {
|
|
39
|
+
log(context.getHelpMessage());
|
|
40
|
+
return gracefulExit();
|
|
41
|
+
}
|
|
42
|
+
if (!versionHandledByUser && context.args.version) {
|
|
43
|
+
log(context.getVersionMessage());
|
|
44
|
+
return gracefulExit();
|
|
45
|
+
}
|
|
46
|
+
return context;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=clirk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clirk.js","sourceRoot":"","sources":["../src/clirk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,OAAO,MAAM,cAAc,CAAC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AAI,EAAE,CAAC;QAC5C,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;QAC9B,OAAO,YAAY,EAAE,CAAC;IACxB,CAAC;IAED,IAAI,CAAC,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAClD,GAAG,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;QACjC,OAAO,YAAY,EAAE,CAAC;IACxB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,222 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clirk.types.js","sourceRoot":"","sources":["../src/clirk.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps a CLI function to catch errors and handle a graceful exit.
|
|
3
|
+
*
|
|
4
|
+
* @param cliFn - The CLI function to wrap.
|
|
5
|
+
* @param workingDir - The working directory for the CLI function.
|
|
6
|
+
*/
|
|
7
|
+
export declare function clitch(cliFn: (workingDir?: string) => Promise<void> | void, workingDir?: string): Promise<void>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { cwd } from 'node:process';
|
|
2
|
+
import { gracefulExit } from '@simbo/graceful-exit';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a CLI function to catch errors and handle a graceful exit.
|
|
5
|
+
*
|
|
6
|
+
* @param cliFn - The CLI function to wrap.
|
|
7
|
+
* @param workingDir - The working directory for the CLI function.
|
|
8
|
+
*/
|
|
9
|
+
export async function clitch(cliFn, workingDir = cwd()) {
|
|
10
|
+
try {
|
|
11
|
+
await cliFn(workingDir);
|
|
12
|
+
await gracefulExit();
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
await gracefulExit(error);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=clitch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clitch.js","sourceRoot":"","sources":["../../src/clitch/clitch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,KAAoD,EAAE,UAAU,GAAG,GAAG,EAAE;IACnG,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,UAAU,CAAC,CAAC;QACxB,MAAM,YAAY,EAAE,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ClirkOptions } from '../clirk.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Adds common CLI flags (e.g. --help, --version) to the Clirk options.
|
|
4
|
+
*
|
|
5
|
+
* This injects their flag definitions, aliases, and descriptions into the
|
|
6
|
+
* minimist options and help text maps.
|
|
7
|
+
*
|
|
8
|
+
* @param input - The original ClirkOptions.
|
|
9
|
+
* @param flags - A map of built-in flags to enable (e.g. `{ help: true }`).
|
|
10
|
+
* @returns A new ClirkOptions object with updated argsOptions and options.
|
|
11
|
+
*/
|
|
12
|
+
export declare function addFlagsToOptions(input: ClirkOptions, flags?: Record<string, boolean>): ClirkOptions;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const FLAGS = ['help', 'version'];
|
|
2
|
+
const FLAG_DESCRIPTIONS = {
|
|
3
|
+
help: 'Display this help message.',
|
|
4
|
+
version: 'Display the package name and version.',
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Adds common CLI flags (e.g. --help, --version) to the Clirk options.
|
|
8
|
+
*
|
|
9
|
+
* This injects their flag definitions, aliases, and descriptions into the
|
|
10
|
+
* minimist options and help text maps.
|
|
11
|
+
*
|
|
12
|
+
* @param input - The original ClirkOptions.
|
|
13
|
+
* @param flags - A map of built-in flags to enable (e.g. `{ help: true }`).
|
|
14
|
+
* @returns A new ClirkOptions object with updated argsOptions and options.
|
|
15
|
+
*/
|
|
16
|
+
export function addFlagsToOptions(input, flags = {}) {
|
|
17
|
+
const result = {
|
|
18
|
+
...input,
|
|
19
|
+
argsOptions: {
|
|
20
|
+
...input.argsOptions,
|
|
21
|
+
boolean: [...new Set(Array.isArray(input.argsOptions?.boolean) ? input.argsOptions.boolean : [])],
|
|
22
|
+
alias: { ...input.argsOptions?.alias },
|
|
23
|
+
},
|
|
24
|
+
options: { ...input.options },
|
|
25
|
+
};
|
|
26
|
+
for (const flag of FLAGS) {
|
|
27
|
+
if (flags[flag]) {
|
|
28
|
+
result.argsOptions.boolean = [...new Set([...result.argsOptions.boolean, flag])];
|
|
29
|
+
result.argsOptions.alias[flag] = [flag[0]];
|
|
30
|
+
if (!(flag in result.options)) {
|
|
31
|
+
result.options[flag] = FLAG_DESCRIPTIONS[flag];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=add-flags-to-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-flags-to-options.js","sourceRoot":"","sources":["../../src/lib/add-flags-to-options.ts"],"names":[],"mappings":"AAEA,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,SAAS,CAAU,CAAC;AAE3C,MAAM,iBAAiB,GAA2B;IAChD,IAAI,EAAE,4BAA4B;IAClC,OAAO,EAAE,uCAAuC;CACjD,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAmB,EAAE,QAAiC,EAAE;IACxF,MAAM,MAAM,GAAG;QACb,GAAG,KAAK;QACR,WAAW,EAAE;YACX,GAAG,KAAK,CAAC,WAAW;YACpB,OAAO,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACjG,KAAK,EAAE,EAAE,GAAG,KAAK,CAAC,WAAW,EAAE,KAAK,EAAE;SACvC;QACD,OAAO,EAAE,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE;KAC9B,CAAC;IAEF,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAChB,MAAM,CAAC,WAAW,CAAC,OAAO,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;YACjF,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3C,IAAI,CAAC,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC9B,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ClirkContextWithoutMessages, ClirkOptions } from '../clirk.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a ClirkContext based on the provided CLI options.
|
|
4
|
+
*
|
|
5
|
+
* This sets up the runtime context needed by clirk, including:
|
|
6
|
+
* - reading the CLI's own package.json
|
|
7
|
+
* - parsing CLI arguments using minimist
|
|
8
|
+
* - normalizing description, examples, usage, parameters, and options
|
|
9
|
+
* - resolving aliases and flag types (boolean/string)
|
|
10
|
+
*
|
|
11
|
+
* @param cliOptions - The user-supplied options for the CLI definition.
|
|
12
|
+
* @returns A promise that resolves to a ClirkContextWithoutMessages object.
|
|
13
|
+
* @throws If `importMeta` is not provided.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createClirkContext(cliOptions: ClirkOptions): Promise<ClirkContextWithoutMessages>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { log } from 'node:console';
|
|
2
|
+
import { basename } from 'node:path';
|
|
3
|
+
import { argv } from 'node:process';
|
|
4
|
+
import { terminated } from '@simbo/cli-output/terminated';
|
|
5
|
+
import { findUpPackage } from '@simbo/find-up-package';
|
|
6
|
+
import { gracefulExit } from '@simbo/graceful-exit';
|
|
7
|
+
import minimist from 'minimist';
|
|
8
|
+
import { parseStringInput } from './parse-string-input.js';
|
|
9
|
+
/**
|
|
10
|
+
* Creates a ClirkContext based on the provided CLI options.
|
|
11
|
+
*
|
|
12
|
+
* This sets up the runtime context needed by clirk, including:
|
|
13
|
+
* - reading the CLI's own package.json
|
|
14
|
+
* - parsing CLI arguments using minimist
|
|
15
|
+
* - normalizing description, examples, usage, parameters, and options
|
|
16
|
+
* - resolving aliases and flag types (boolean/string)
|
|
17
|
+
*
|
|
18
|
+
* @param cliOptions - The user-supplied options for the CLI definition.
|
|
19
|
+
* @returns A promise that resolves to a ClirkContextWithoutMessages object.
|
|
20
|
+
* @throws If `importMeta` is not provided.
|
|
21
|
+
*/
|
|
22
|
+
export async function createClirkContext(cliOptions) {
|
|
23
|
+
if (!cliOptions.importMeta) {
|
|
24
|
+
throw new Error('The importMeta option is required.');
|
|
25
|
+
}
|
|
26
|
+
const pkg = await findUpPackage({
|
|
27
|
+
workingDir: cliOptions.importMeta,
|
|
28
|
+
normalize: true,
|
|
29
|
+
});
|
|
30
|
+
if (pkg === undefined) {
|
|
31
|
+
throw new Error(`Could not find package for path: ${cliOptions.importMeta}`);
|
|
32
|
+
}
|
|
33
|
+
const commandName = basename(argv[1]);
|
|
34
|
+
const { argsOptions = {}, title, name, description = pkg.packageJson.description, icon, usage = [], usageLabel = 'USAGE', parametersLabel = 'PARAMETERS', optionsLabel = 'OPTIONS', } = cliOptions;
|
|
35
|
+
const args = minimist(argv.slice(2), argsOptions);
|
|
36
|
+
const parameters = getParametersMap(cliOptions);
|
|
37
|
+
const options = getOptionsMap(cliOptions);
|
|
38
|
+
const examples = getExamples(cliOptions);
|
|
39
|
+
const { sigintHandler, sigintMessage } = getSigintHandler(cliOptions);
|
|
40
|
+
return {
|
|
41
|
+
argsOptions,
|
|
42
|
+
args,
|
|
43
|
+
title,
|
|
44
|
+
name,
|
|
45
|
+
commandName,
|
|
46
|
+
package: pkg,
|
|
47
|
+
description: parseStringInput(description),
|
|
48
|
+
examples,
|
|
49
|
+
usage: parseStringInput(usage),
|
|
50
|
+
usageLabel,
|
|
51
|
+
parameters,
|
|
52
|
+
parametersLabel,
|
|
53
|
+
options,
|
|
54
|
+
optionsLabel,
|
|
55
|
+
icon,
|
|
56
|
+
sigintHandler,
|
|
57
|
+
sigintMessage,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Parses the parameters from the CLI options.
|
|
62
|
+
*
|
|
63
|
+
* This function extracts the parameters and their descriptions from the `parameters`
|
|
64
|
+
* field of the CLI options.
|
|
65
|
+
*
|
|
66
|
+
* @param cliOptions - The user-supplied options for the CLI definition.
|
|
67
|
+
* @returns A Map of parameter names to their descriptions.
|
|
68
|
+
*/
|
|
69
|
+
function getParametersMap(cliOptions) {
|
|
70
|
+
const { parameters = {} } = cliOptions;
|
|
71
|
+
return new Map(Object.entries(parameters).map(([key, value]) => [key, { description: parseStringInput(value) }]));
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Parses the options from the CLI options.
|
|
75
|
+
*
|
|
76
|
+
* This function extracts the options and their properties from the `options`
|
|
77
|
+
* and `argsOptions` fields of the CLI options.
|
|
78
|
+
*
|
|
79
|
+
* @param cliOptions - The user-supplied options for the CLI definition.
|
|
80
|
+
* @returns A Map of option names to their descriptions and properties.
|
|
81
|
+
*/
|
|
82
|
+
function getOptionsMap(cliOptions) {
|
|
83
|
+
const { argsOptions = {}, options = {} } = cliOptions;
|
|
84
|
+
return new Map(Object.entries(options).map(([key, value]) => {
|
|
85
|
+
const optionDescription = parseStringInput(value);
|
|
86
|
+
const aliases = argsOptions.alias?.[key]
|
|
87
|
+
? new Set(Array.isArray(argsOptions.alias[key]) ? argsOptions.alias[key] : [argsOptions.alias[key]])
|
|
88
|
+
: new Set();
|
|
89
|
+
const isBoolean = argsOptions.boolean === true || (Array.isArray(argsOptions.boolean) && argsOptions.boolean.includes(key));
|
|
90
|
+
const isString = Array.isArray(argsOptions.string) && argsOptions.string.includes(key);
|
|
91
|
+
return [key, { description: optionDescription, aliases, isBoolean, isString }];
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Parses the examples from the CLI options.
|
|
96
|
+
*
|
|
97
|
+
* If no examples are provided, it defaults to using the command name.
|
|
98
|
+
* If examples are provided as a string, they are split into an array.
|
|
99
|
+
*
|
|
100
|
+
* @param cliOptions - The user-supplied options for the CLI definition.
|
|
101
|
+
* @returns An array of example strings.
|
|
102
|
+
*/
|
|
103
|
+
function getExamples(cliOptions) {
|
|
104
|
+
const { name, examples = [] } = cliOptions;
|
|
105
|
+
const parsedExamples = parseStringInput(examples);
|
|
106
|
+
return parsedExamples.length === 0 ? [name] : parsedExamples;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Returns the SIGINT handler and message based on the provided CLI options.
|
|
110
|
+
*
|
|
111
|
+
* If a custom handler function is provided, it will be used.
|
|
112
|
+
* If `sigintHandler` is set to false, no handler will be created.
|
|
113
|
+
* If no custom handler is provided, a default handler will log a message and
|
|
114
|
+
* exit gracefully.
|
|
115
|
+
*
|
|
116
|
+
* @param cliOptions - The user-supplied options for the CLI definition.
|
|
117
|
+
* @returns An object containing the sigintHandler function and sigintMessage
|
|
118
|
+
* string.
|
|
119
|
+
*/
|
|
120
|
+
function getSigintHandler(cliOptions) {
|
|
121
|
+
const { sigintHandler: fn, sigintMessage: msg } = cliOptions;
|
|
122
|
+
const sigintMessage = typeof msg === 'string' && msg.length > 0 ? msg : terminated('Received SIGINT');
|
|
123
|
+
const sigintHandler = fn === false
|
|
124
|
+
? undefined
|
|
125
|
+
: typeof fn === 'function'
|
|
126
|
+
? fn
|
|
127
|
+
: async () => {
|
|
128
|
+
log(sigintMessage);
|
|
129
|
+
await gracefulExit(undefined, 1);
|
|
130
|
+
};
|
|
131
|
+
return { sigintHandler, sigintMessage };
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=create-clirk-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-clirk-context.js","sourceRoot":"","sources":["../../src/lib/create-clirk-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,OAAO,EA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AC,UAAU,CAAC,iBAAiB,CAAC,CAAC;IACtG,MAAM,aAAa,GACjB,EAAE,KAAK,KAAK;QACV,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,OAAO,EAAE,KAAK,UAAU;YACxB,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,KAAK,IAAI,EAAE;gBACT,GAAG,CAAC,aAAa,CAAC,CAAC;gBACnB,MAAM,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;YACnC,CAAC,CAAC;IACV,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ClirkContextWithoutMessages } from '../clirk.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generates a help message for the CLI based on the provided context.
|
|
4
|
+
*
|
|
5
|
+
* @param context - The context containing CLI information such as title, name,
|
|
6
|
+
* description, examples, usage, parameters, and options.
|
|
7
|
+
* @returns A formatted string containing the help message.
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateHelpMessage(context: ClirkContextWithoutMessages): string;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { plural } from '@simbo/plural';
|
|
2
|
+
import { bold, cyan, dim, underline, yellow } from 'yoctocolors';
|
|
3
|
+
/**
|
|
4
|
+
* Generates a help message for the CLI based on the provided context.
|
|
5
|
+
*
|
|
6
|
+
* @param context - The context containing CLI information such as title, name,
|
|
7
|
+
* description, examples, usage, parameters, and options.
|
|
8
|
+
* @returns A formatted string containing the help message.
|
|
9
|
+
*/
|
|
10
|
+
export function generateHelpMessage(context) {
|
|
11
|
+
const output = [
|
|
12
|
+
...getHeader(context),
|
|
13
|
+
...getUsage(context),
|
|
14
|
+
...getParameters(context),
|
|
15
|
+
...getOptions(context),
|
|
16
|
+
];
|
|
17
|
+
return `\n${output.join('\n\n')}\n`;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Generates the header for the CLI help message as an array of sections that
|
|
21
|
+
* will later be joined with blank lines.
|
|
22
|
+
*
|
|
23
|
+
* @param context - The context containing CLI information such as package name and version.
|
|
24
|
+
* @returns An array of strings representing the header section.
|
|
25
|
+
*/
|
|
26
|
+
function getHeader(context) {
|
|
27
|
+
const { icon, title, name, description, package: { packageJson: { name: packageName, version, homepage }, }, } = context;
|
|
28
|
+
return [
|
|
29
|
+
`${icon ? `${icon} ` : ''}${bold(cyan(`${name} â ${title}`))}`,
|
|
30
|
+
`${packageName} v${version}${homepage ? `\n${dim(underline(homepage))}` : ''}`,
|
|
31
|
+
description.join('\n'),
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Generates the usage section of the CLI help message as an array of sections
|
|
36
|
+
* that will later be joined with blank lines.
|
|
37
|
+
*
|
|
38
|
+
* @param context - The context containing CLI information such as examples and usage.
|
|
39
|
+
* @returns An array of strings representing the usage section.
|
|
40
|
+
*/
|
|
41
|
+
function getUsage(context) {
|
|
42
|
+
const { examples, usage, usageLabel } = context;
|
|
43
|
+
return [
|
|
44
|
+
bold(`${usageLabel}:`),
|
|
45
|
+
` ${yellow(examples.join('\n '))}`,
|
|
46
|
+
...(usage.length > 0 ? [` ${usage.join('\n ')}`] : []),
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Generates the parameters section of the CLI help message as an array of sections
|
|
51
|
+
* that will later be joined with blank lines.
|
|
52
|
+
*
|
|
53
|
+
* @param context - The context containing CLI information such as parameters and their descriptions.
|
|
54
|
+
* @returns An array of strings representing the parameters section.
|
|
55
|
+
*/
|
|
56
|
+
function getParameters(context) {
|
|
57
|
+
const { parameters, parametersLabel } = context;
|
|
58
|
+
if (parameters.size === 0) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
const output = [bold(`${parametersLabel}:`)];
|
|
62
|
+
for (const [key, { description }] of parameters.entries()) {
|
|
63
|
+
output.push(` ${yellow(key)}\n ${description.join('\n ')}`);
|
|
64
|
+
}
|
|
65
|
+
return output;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Generates the options section of the CLI help message as an array of sections
|
|
69
|
+
* that will later be joined with blank lines.
|
|
70
|
+
*
|
|
71
|
+
* @param context - The context containing CLI information such as options and their descriptions.
|
|
72
|
+
* @returns An array of strings representing the options section.
|
|
73
|
+
*/
|
|
74
|
+
function getOptions(context) {
|
|
75
|
+
const { options, optionsLabel } = context;
|
|
76
|
+
if (options.size === 0) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
const output = [bold(`${optionsLabel}:`)];
|
|
80
|
+
for (const [key, { description, aliases, isString }] of options.entries()) {
|
|
81
|
+
const value = isString ? dim('=<VALUE>') : '';
|
|
82
|
+
let aliasDescription = ` ${yellow(`--${key}`)}${value}\n ${description.join('\n ')}`;
|
|
83
|
+
if (aliases.size > 0) {
|
|
84
|
+
const aliasList = [...aliases].map(alias => (alias.length === 1 ? `-${alias}` : `--${alias}`)).join(', ');
|
|
85
|
+
aliasDescription += `\n ${dim(`${plural(aliases.size, 'Alias', 'Aliases', '%s')}: ${aliasList}`)}`;
|
|
86
|
+
}
|
|
87
|
+
output.push(aliasDescription);
|
|
88
|
+
}
|
|
89
|
+
return output;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=generate-help-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-help-message.js","sourceRoot":"","sources":["../../src/lib/generate-help-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIjE;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAoC;IACtE,MAAM,MAAM,GAAa;QACvB,GAAG,SAAS,CAAC,OAAO,CAAC;QACrB,GAAG,QAAQ,CAAC,OAAO,CAAC;Q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S,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1G,gBAAgB,IAAI,SAAS,GAAG,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC,EAAE,CAAC;QACxG,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ClirkContextWithoutMessages } from '../clirk.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generates a version message for the CLI package.
|
|
4
|
+
*
|
|
5
|
+
* @param context - The context containing package information.
|
|
6
|
+
* @returns A string message containing the package name and version.
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateVersionMessage(context: ClirkContextWithoutMessages): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a version message for the CLI package.
|
|
3
|
+
*
|
|
4
|
+
* @param context - The context containing package information.
|
|
5
|
+
* @returns A string message containing the package name and version.
|
|
6
|
+
*/
|
|
7
|
+
export function generateVersionMessage(context) {
|
|
8
|
+
const { package: { packageJson: { name, version }, }, } = context;
|
|
9
|
+
return `${name} v${version}`;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=generate-version-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-version-message.js","sourceRoot":"","sources":["../../src/lib/generate-version-message.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAoC;IACzE,MAAM,EACJ,OAAO,EAAE,EACP,WAAW,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,GAC/B,GACF,GAAG,OAAO,CAAC;IAEZ,OAAO,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
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;
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
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[];
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@simbo/clirk",
|
|
3
|
+
"description": "A utility that simplifies creating Node.js CLIs and provides common CLI functionalities out of the box.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"author": "Simon Lepel <simbo@simbo.de> (https://simbo.de/)",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "http://github.com/simbo/packages/tree/main/packages/clirk",
|
|
8
|
+
"repository": "github:simbo/packages",
|
|
9
|
+
"bugs": "https://github.com/simbo/packages/issues",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"cli",
|
|
12
|
+
"framework",
|
|
13
|
+
"clirk",
|
|
14
|
+
"command-line",
|
|
15
|
+
"arguments",
|
|
16
|
+
"help",
|
|
17
|
+
"version",
|
|
18
|
+
"exit",
|
|
19
|
+
"graceful-exit",
|
|
20
|
+
"utilities",
|
|
21
|
+
"tooling",
|
|
22
|
+
"typescript"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=20"
|
|
26
|
+
},
|
|
27
|
+
"type": "module",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": "./dist/index.js",
|
|
30
|
+
"./clitch": "./dist/clitch/clitch.js"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"CHANGELOG.md",
|
|
34
|
+
"dist",
|
|
35
|
+
"LICENSE.md",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"minimist": "^1.2.8",
|
|
40
|
+
"yoctocolors": "^2.1.1",
|
|
41
|
+
"@simbo/find-up-package": "1.0.0",
|
|
42
|
+
"@simbo/plural": "1.0.0",
|
|
43
|
+
"@simbo/cli-output": "1.0.0",
|
|
44
|
+
"@simbo/graceful-exit": "1.0.1",
|
|
45
|
+
"@simbo/stringify-error": "1.0.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@ianvs/prettier-plugin-sort-imports": "^4.6.2",
|
|
49
|
+
"@types/node": "^20.19.11",
|
|
50
|
+
"@types/minimist": "^1.2.5",
|
|
51
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
52
|
+
"@vitest/ui": "^3.2.4",
|
|
53
|
+
"eslint": "^9.34.0",
|
|
54
|
+
"jiti": "^2.5.1",
|
|
55
|
+
"prettier": "^3.6.2",
|
|
56
|
+
"prettier-plugin-organize-attributes": "^1.0.0",
|
|
57
|
+
"typescript": "^5.9.2",
|
|
58
|
+
"vitest": "^3.2.4",
|
|
59
|
+
"@simbo/tsconfig": "1.0.3",
|
|
60
|
+
"@simbo/eslint-config": "1.0.2",
|
|
61
|
+
"@simbo/prettier-config": "1.0.3"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "tsc --project tsconfig.build.json",
|
|
65
|
+
"check:eslint": "eslint --config ./eslint.config.ts --max-warnings 0",
|
|
66
|
+
"check:format": "prettier --check .",
|
|
67
|
+
"check:types": "tsc --noEmit",
|
|
68
|
+
"clean:dist": "rm -rf dist",
|
|
69
|
+
"fix:eslint": "pnpm run check:eslint --fix",
|
|
70
|
+
"fix:format": "prettier --write .",
|
|
71
|
+
"test": "vitest run --coverage",
|
|
72
|
+
"test:ui": "pnpm run test:watch --ui",
|
|
73
|
+
"test:watch": "vitest dev --coverage"
|
|
74
|
+
}
|
|
75
|
+
}
|