@bemoje/cli 0.2.0 → 0.3.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/index.d.ts +6 -0
- package/index.js +6 -0
- package/lib/Command.d.ts +293 -0
- package/lib/Command.js +435 -0
- package/lib/CommandHelpAdapter.d.ts +157 -0
- package/lib/CommandHelpAdapter.js +100 -0
- package/lib/CommanderHelpAdapter.d.ts +56 -0
- package/lib/CommanderHelpAdapter.js +90 -0
- package/lib/Help.d.ts +263 -0
- package/lib/Help.js +477 -0
- package/lib/internal/lazyProp.d.ts +5 -0
- package/lib/internal/lazyProp.js +24 -0
- package/lib/renderHelp.d.ts +6 -0
- package/lib/renderHelp.js +12 -0
- package/package.json +25 -37
- package/LICENSE +0 -21
- package/README.md +0 -34
- package/cjs/arg/ArgumentBuilder.d.ts +0 -23
- package/cjs/arg/ArgumentBuilder.d.ts.map +0 -1
- package/cjs/arg/ArgumentBuilder.js +0 -52
- package/cjs/arg/ArgumentBuilder.js.map +0 -1
- package/cjs/arg/ArgumentParserSelector.d.ts +0 -9
- package/cjs/arg/ArgumentParserSelector.d.ts.map +0 -1
- package/cjs/arg/ArgumentParserSelector.js +0 -15
- package/cjs/arg/ArgumentParserSelector.js.map +0 -1
- package/cjs/arg/ArgumentReader.d.ts +0 -15
- package/cjs/arg/ArgumentReader.d.ts.map +0 -1
- package/cjs/arg/ArgumentReader.js +0 -38
- package/cjs/arg/ArgumentReader.js.map +0 -1
- package/cjs/arg/ArgumentValidatorSelector.d.ts +0 -8
- package/cjs/arg/ArgumentValidatorSelector.d.ts.map +0 -1
- package/cjs/arg/ArgumentValidatorSelector.js +0 -16
- package/cjs/arg/ArgumentValidatorSelector.js.map +0 -1
- package/cjs/cmd/CommandBuilder.d.ts +0 -410
- package/cjs/cmd/CommandBuilder.d.ts.map +0 -1
- package/cjs/cmd/CommandBuilder.js +0 -1277
- package/cjs/cmd/CommandBuilder.js.map +0 -1
- package/cjs/cmd/CommandBuilderMetaData.d.ts +0 -26
- package/cjs/cmd/CommandBuilderMetaData.d.ts.map +0 -1
- package/cjs/cmd/CommandBuilderMetaData.js +0 -45
- package/cjs/cmd/CommandBuilderMetaData.js.map +0 -1
- package/cjs/cmd/CommandFeatureSelector.d.ts +0 -80
- package/cjs/cmd/CommandFeatureSelector.d.ts.map +0 -1
- package/cjs/cmd/CommandFeatureSelector.js +0 -114
- package/cjs/cmd/CommandFeatureSelector.js.map +0 -1
- package/cjs/cmd/DefaultHelpConfig.d.ts +0 -29
- package/cjs/cmd/DefaultHelpConfig.d.ts.map +0 -1
- package/cjs/cmd/DefaultHelpConfig.js +0 -177
- package/cjs/cmd/DefaultHelpConfig.js.map +0 -1
- package/cjs/cmd/commanderBackRefs.d.ts +0 -10
- package/cjs/cmd/commanderBackRefs.d.ts.map +0 -1
- package/cjs/cmd/commanderBackRefs.js +0 -38
- package/cjs/cmd/commanderBackRefs.js.map +0 -1
- package/cjs/core/OutputManager.d.ts +0 -64
- package/cjs/core/OutputManager.d.ts.map +0 -1
- package/cjs/core/OutputManager.js +0 -92
- package/cjs/core/OutputManager.js.map +0 -1
- package/cjs/core/ParserSelector.d.ts +0 -23
- package/cjs/core/ParserSelector.d.ts.map +0 -1
- package/cjs/core/ParserSelector.js +0 -46
- package/cjs/core/ParserSelector.js.map +0 -1
- package/cjs/core/ValidatorSelector.d.ts +0 -19
- package/cjs/core/ValidatorSelector.d.ts.map +0 -1
- package/cjs/core/ValidatorSelector.js +0 -42
- package/cjs/core/ValidatorSelector.js.map +0 -1
- package/cjs/core/splitCombinedArgvShorts.d.ts +0 -2
- package/cjs/core/splitCombinedArgvShorts.d.ts.map +0 -1
- package/cjs/core/splitCombinedArgvShorts.js +0 -15
- package/cjs/core/splitCombinedArgvShorts.js.map +0 -1
- package/cjs/db/AbstractJsonFileSection.d.ts +0 -136
- package/cjs/db/AbstractJsonFileSection.d.ts.map +0 -1
- package/cjs/db/AbstractJsonFileSection.js +0 -190
- package/cjs/db/AbstractJsonFileSection.js.map +0 -1
- package/cjs/db/AppDataSection.d.ts +0 -31
- package/cjs/db/AppDataSection.d.ts.map +0 -1
- package/cjs/db/AppDataSection.js +0 -49
- package/cjs/db/AppDataSection.js.map +0 -1
- package/cjs/db/ConfigSection.d.ts +0 -46
- package/cjs/db/ConfigSection.d.ts.map +0 -1
- package/cjs/db/ConfigSection.js +0 -71
- package/cjs/db/ConfigSection.js.map +0 -1
- package/cjs/db/JsonFile.d.ts +0 -36
- package/cjs/db/JsonFile.d.ts.map +0 -1
- package/cjs/db/JsonFile.js +0 -60
- package/cjs/db/JsonFile.js.map +0 -1
- package/cjs/db/PresetsSection.d.ts +0 -45
- package/cjs/db/PresetsSection.d.ts.map +0 -1
- package/cjs/db/PresetsSection.js +0 -82
- package/cjs/db/PresetsSection.js.map +0 -1
- package/cjs/index.d.ts +0 -26
- package/cjs/index.d.ts.map +0 -1
- package/cjs/index.js +0 -29
- package/cjs/index.js.map +0 -1
- package/cjs/opt/OptionArgumentParserSelector.d.ts +0 -8
- package/cjs/opt/OptionArgumentParserSelector.d.ts.map +0 -1
- package/cjs/opt/OptionArgumentParserSelector.js +0 -16
- package/cjs/opt/OptionArgumentParserSelector.js.map +0 -1
- package/cjs/opt/OptionArgumentValidatorSelector.d.ts +0 -8
- package/cjs/opt/OptionArgumentValidatorSelector.d.ts.map +0 -1
- package/cjs/opt/OptionArgumentValidatorSelector.js +0 -19
- package/cjs/opt/OptionArgumentValidatorSelector.js.map +0 -1
- package/cjs/opt/OptionBuilder.d.ts +0 -32
- package/cjs/opt/OptionBuilder.d.ts.map +0 -1
- package/cjs/opt/OptionBuilder.js +0 -97
- package/cjs/opt/OptionBuilder.js.map +0 -1
- package/cjs/opt/OptionHelpers.d.ts +0 -33
- package/cjs/opt/OptionHelpers.d.ts.map +0 -1
- package/cjs/opt/OptionHelpers.js +0 -57
- package/cjs/opt/OptionHelpers.js.map +0 -1
- package/cjs/opt/OptionReader.d.ts +0 -24
- package/cjs/opt/OptionReader.d.ts.map +0 -1
- package/cjs/opt/OptionReader.js +0 -66
- package/cjs/opt/OptionReader.js.map +0 -1
- package/cjs/types/IConfig.d.ts +0 -22
- package/cjs/types/IConfig.d.ts.map +0 -1
- package/cjs/types/IConfig.js +0 -3
- package/cjs/types/IConfig.js.map +0 -1
- package/cjs/types/IPreset.d.ts +0 -15
- package/cjs/types/IPreset.d.ts.map +0 -1
- package/cjs/types/IPreset.js +0 -3
- package/cjs/types/IPreset.js.map +0 -1
package/lib/Help.js
ADDED
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
const _Help = class _Help {
|
|
6
|
+
constructor() {
|
|
7
|
+
/** output helpWidth, long lines are wrapped to fit */
|
|
8
|
+
__publicField(this, "helpWidth", process.stdout.isTTY ? process.stdout.columns : 80);
|
|
9
|
+
__publicField(this, "minWidthToWrap", 40);
|
|
10
|
+
__publicField(this, "sortSubcommands");
|
|
11
|
+
__publicField(this, "sortOptions");
|
|
12
|
+
__publicField(this, "showGlobalOptions");
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
16
|
+
*/
|
|
17
|
+
visibleCommands(cmd) {
|
|
18
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2.hidden);
|
|
19
|
+
if (this.sortSubcommands) {
|
|
20
|
+
visibleCommands.sort((a, b) => {
|
|
21
|
+
return a.name.localeCompare(b.name);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return visibleCommands;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Compare options for sort.
|
|
28
|
+
*/
|
|
29
|
+
compareOptions(a, b) {
|
|
30
|
+
const getSortKey = /* @__PURE__ */ __name((option) => {
|
|
31
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
32
|
+
}, "getSortKey");
|
|
33
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
|
|
37
|
+
*/
|
|
38
|
+
visibleOptions(cmd) {
|
|
39
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
40
|
+
if (this.sortOptions) {
|
|
41
|
+
visibleOptions.sort(this.compareOptions);
|
|
42
|
+
}
|
|
43
|
+
return visibleOptions;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get an array of the visible global options. (Not including help.)
|
|
47
|
+
*/
|
|
48
|
+
visibleGlobalOptions(cmd) {
|
|
49
|
+
if (!this.showGlobalOptions) return [];
|
|
50
|
+
const globalOptions = [];
|
|
51
|
+
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
52
|
+
const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
|
|
53
|
+
globalOptions.push(...visibleOptions);
|
|
54
|
+
}
|
|
55
|
+
if (this.sortOptions) {
|
|
56
|
+
globalOptions.sort(this.compareOptions);
|
|
57
|
+
}
|
|
58
|
+
return globalOptions;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get an array of the arguments if any have a description.
|
|
62
|
+
*/
|
|
63
|
+
visibleArguments(cmd) {
|
|
64
|
+
if (cmd.arguments.find((argument) => argument.description)) {
|
|
65
|
+
return [...cmd.arguments];
|
|
66
|
+
}
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get the command term to show in the list of subcommands.
|
|
71
|
+
*/
|
|
72
|
+
subcommandTerm(cmd) {
|
|
73
|
+
const args = cmd.arguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
74
|
+
return cmd.name + (cmd.aliases[0] ? "|" + cmd.aliases[0] : "") + (cmd.options.length ? " [options]" : "") + // simplistic check for non-help option
|
|
75
|
+
(args ? " " + args : "");
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get the option term to show in the list of options.
|
|
79
|
+
*/
|
|
80
|
+
optionTerm(option) {
|
|
81
|
+
return option.flags;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get the argument term to show in the list of arguments.
|
|
85
|
+
*/
|
|
86
|
+
argumentTerm(argument) {
|
|
87
|
+
return argument.name;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get the longest command term length.
|
|
91
|
+
*/
|
|
92
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
93
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
94
|
+
return Math.max(max, this.displayWidth(helper.styleSubcommandTerm(helper.subcommandTerm(command))));
|
|
95
|
+
}, 0);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get the longest option term length.
|
|
99
|
+
*/
|
|
100
|
+
longestOptionTermLength(cmd, helper) {
|
|
101
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
102
|
+
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
103
|
+
}, 0);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get the longest global option term length.
|
|
107
|
+
*/
|
|
108
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
109
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
110
|
+
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
111
|
+
}, 0);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get the longest argument term length.
|
|
115
|
+
*/
|
|
116
|
+
longestArgumentTermLength(cmd, helper) {
|
|
117
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
118
|
+
return Math.max(max, this.displayWidth(helper.styleArgumentTerm(helper.argumentTerm(argument))));
|
|
119
|
+
}, 0);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get the command usage to be displayed at the top of the built-in help.
|
|
123
|
+
*/
|
|
124
|
+
commandUsage(cmd) {
|
|
125
|
+
let cmdName = cmd.name;
|
|
126
|
+
if (cmd.aliases[0]) {
|
|
127
|
+
cmdName = cmdName + "|" + cmd.aliases[0];
|
|
128
|
+
}
|
|
129
|
+
let ancestorCmdNames = "";
|
|
130
|
+
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
131
|
+
ancestorCmdNames = ancestorCmd.name + " " + ancestorCmdNames;
|
|
132
|
+
}
|
|
133
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get the description for the command.
|
|
137
|
+
*/
|
|
138
|
+
commandDescription(cmd) {
|
|
139
|
+
return cmd.description;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get the subcommand summary to show in the list of subcommands.
|
|
143
|
+
* (Fallback to description for backwards compatibility.)
|
|
144
|
+
*/
|
|
145
|
+
subcommandDescription(cmd) {
|
|
146
|
+
return cmd.summary || cmd.description;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get the option description to show in the list of options.
|
|
150
|
+
*/
|
|
151
|
+
optionDescription(option) {
|
|
152
|
+
const extraInfo = [];
|
|
153
|
+
if (option.choices) {
|
|
154
|
+
extraInfo.push(
|
|
155
|
+
// use stringify to match the display of the default value
|
|
156
|
+
`choices: ${option.choices.map((choice) => String(choice)).join(", ")}`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
if (option.defaultValue !== void 0) {
|
|
160
|
+
const boolean = !option.required && !option.optional && !option.negate;
|
|
161
|
+
const showDefault = option.required || option.optional || boolean && typeof option.defaultValue === "boolean";
|
|
162
|
+
if (showDefault) {
|
|
163
|
+
extraInfo.push(`default: ${option.defaultValueDescription || String(option.defaultValue)}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (option.env !== void 0) {
|
|
167
|
+
extraInfo.push(`env: ${option.env}`);
|
|
168
|
+
}
|
|
169
|
+
if (extraInfo.length > 0) {
|
|
170
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
171
|
+
if (option.description) {
|
|
172
|
+
return `${option.description} ${extraDescription}`;
|
|
173
|
+
}
|
|
174
|
+
return extraDescription;
|
|
175
|
+
}
|
|
176
|
+
return option.description;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get the argument description to show in the list of arguments.
|
|
180
|
+
*/
|
|
181
|
+
argumentDescription(argument) {
|
|
182
|
+
const extraInfo = [];
|
|
183
|
+
if (argument.choices) {
|
|
184
|
+
extraInfo.push(
|
|
185
|
+
// use stringify to match the display of the default value
|
|
186
|
+
`choices: ${argument.choices.map((choice) => String(choice)).join(", ")}`
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
if (argument.defaultValue !== void 0) {
|
|
190
|
+
extraInfo.push(`default: ${argument.defaultValueDescription || String(argument.defaultValue)}`);
|
|
191
|
+
}
|
|
192
|
+
if (extraInfo.length > 0) {
|
|
193
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
194
|
+
if (argument.description) {
|
|
195
|
+
return `${argument.description} ${extraDescription}`;
|
|
196
|
+
}
|
|
197
|
+
return extraDescription;
|
|
198
|
+
}
|
|
199
|
+
return argument.description;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Format a list of items, given a heading and an array of formatted items.
|
|
203
|
+
*/
|
|
204
|
+
formatItemList(heading, items, helper) {
|
|
205
|
+
if (items.length === 0) return [];
|
|
206
|
+
return [helper.styleTitle(heading), ...items, ""];
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Group items by their help group heading.
|
|
210
|
+
*/
|
|
211
|
+
groupItems(unsortedItems, visibleItems, getGroup) {
|
|
212
|
+
const result = /* @__PURE__ */ new Map();
|
|
213
|
+
unsortedItems.forEach((item) => {
|
|
214
|
+
const group = getGroup(item);
|
|
215
|
+
if (!result.has(group)) result.set(group, []);
|
|
216
|
+
});
|
|
217
|
+
visibleItems.forEach((item) => {
|
|
218
|
+
const group = getGroup(item);
|
|
219
|
+
if (!result.has(group)) {
|
|
220
|
+
result.set(group, []);
|
|
221
|
+
}
|
|
222
|
+
result.get(group).push(item);
|
|
223
|
+
});
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Generate the built-in help text.
|
|
228
|
+
*/
|
|
229
|
+
formatHelp(cmd, helper) {
|
|
230
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
231
|
+
const helpWidth = helper.helpWidth;
|
|
232
|
+
function callFormatItem(term, description) {
|
|
233
|
+
return helper.formatItem(term, termWidth, description, helper);
|
|
234
|
+
}
|
|
235
|
+
__name(callFormatItem, "callFormatItem");
|
|
236
|
+
let output = [`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`, ""];
|
|
237
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
238
|
+
if (commandDescription.length > 0) {
|
|
239
|
+
output = output.concat([helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth), ""]);
|
|
240
|
+
}
|
|
241
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
242
|
+
return callFormatItem(
|
|
243
|
+
helper.styleArgumentTerm(helper.argumentTerm(argument)),
|
|
244
|
+
helper.styleArgumentDescription(helper.argumentDescription(argument))
|
|
245
|
+
);
|
|
246
|
+
});
|
|
247
|
+
output = output.concat(this.formatItemList("Arguments:", argumentList, helper));
|
|
248
|
+
const optionGroups = this.groupItems(
|
|
249
|
+
cmd.options,
|
|
250
|
+
helper.visibleOptions(cmd),
|
|
251
|
+
(option) => option.group ?? "Options:"
|
|
252
|
+
);
|
|
253
|
+
optionGroups.forEach((options, group) => {
|
|
254
|
+
const optionList = options.map((option) => {
|
|
255
|
+
return callFormatItem(
|
|
256
|
+
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
257
|
+
helper.styleOptionDescription(helper.optionDescription(option))
|
|
258
|
+
);
|
|
259
|
+
});
|
|
260
|
+
output = output.concat(this.formatItemList(group, optionList, helper));
|
|
261
|
+
});
|
|
262
|
+
if (helper.showGlobalOptions) {
|
|
263
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
264
|
+
return callFormatItem(
|
|
265
|
+
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
266
|
+
helper.styleOptionDescription(helper.optionDescription(option))
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
|
|
270
|
+
}
|
|
271
|
+
const commandGroups = this.groupItems(
|
|
272
|
+
cmd.commands,
|
|
273
|
+
helper.visibleCommands(cmd),
|
|
274
|
+
(sub) => sub.group || "Commands:"
|
|
275
|
+
);
|
|
276
|
+
commandGroups.forEach((commands, group) => {
|
|
277
|
+
const commandList = commands.map((sub) => {
|
|
278
|
+
return callFormatItem(
|
|
279
|
+
helper.styleSubcommandTerm(helper.subcommandTerm(sub)),
|
|
280
|
+
helper.styleSubcommandDescription(helper.subcommandDescription(sub))
|
|
281
|
+
);
|
|
282
|
+
});
|
|
283
|
+
output = output.concat(this.formatItemList(group, commandList, helper));
|
|
284
|
+
});
|
|
285
|
+
return output.join("\n");
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations.
|
|
289
|
+
*/
|
|
290
|
+
displayWidth(str) {
|
|
291
|
+
return stripColor(str).length;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.
|
|
295
|
+
*/
|
|
296
|
+
styleTitle(str) {
|
|
297
|
+
return str;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Style the usage line for displaying in the help. Applies specific styling to different parts like options, commands, and arguments.
|
|
301
|
+
*/
|
|
302
|
+
styleUsage(str) {
|
|
303
|
+
return str.split(" ").map((word) => {
|
|
304
|
+
if (word === "[options]") return this.styleOptionText(word);
|
|
305
|
+
if (word === "[command]") return this.styleSubcommandText(word);
|
|
306
|
+
if (word[0] === "[" || word[0] === "<") return this.styleArgumentText(word);
|
|
307
|
+
return this.styleCommandText(word);
|
|
308
|
+
}).join(" ");
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Style command descriptions for display in help output.
|
|
312
|
+
*/
|
|
313
|
+
styleCommandDescription(str) {
|
|
314
|
+
return this.styleDescriptionText(str);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Style option descriptions for display in help output.
|
|
318
|
+
*/
|
|
319
|
+
styleOptionDescription(str) {
|
|
320
|
+
return this.styleDescriptionText(str);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Style subcommand descriptions for display in help output.
|
|
324
|
+
*/
|
|
325
|
+
styleSubcommandDescription(str) {
|
|
326
|
+
return this.styleDescriptionText(str);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Style argument descriptions for display in help output.
|
|
330
|
+
*/
|
|
331
|
+
styleArgumentDescription(str) {
|
|
332
|
+
return this.styleDescriptionText(str);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Base style used by descriptions. Override in subclass to apply custom formatting.
|
|
336
|
+
*/
|
|
337
|
+
styleDescriptionText(str) {
|
|
338
|
+
return str;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Style option terms (flags) for display in help output.
|
|
342
|
+
*/
|
|
343
|
+
styleOptionTerm(str) {
|
|
344
|
+
return this.styleOptionText(str);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Style subcommand terms for display in help output. Applies specific styling to different parts like options and arguments.
|
|
348
|
+
*/
|
|
349
|
+
styleSubcommandTerm(str) {
|
|
350
|
+
return str.split(" ").map((word) => {
|
|
351
|
+
if (word === "[options]") return this.styleOptionText(word);
|
|
352
|
+
if (word[0] === "[" || word[0] === "<") return this.styleArgumentText(word);
|
|
353
|
+
return this.styleSubcommandText(word);
|
|
354
|
+
}).join(" ");
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Style argument terms for display in help output.
|
|
358
|
+
*/
|
|
359
|
+
styleArgumentTerm(str) {
|
|
360
|
+
return this.styleArgumentText(str);
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Base style used in terms and usage for options. Override in subclass to apply custom formatting.
|
|
364
|
+
*/
|
|
365
|
+
styleOptionText(str) {
|
|
366
|
+
return str;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Base style used in terms and usage for arguments. Override in subclass to apply custom formatting.
|
|
370
|
+
*/
|
|
371
|
+
styleArgumentText(str) {
|
|
372
|
+
return str;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Base style used in terms and usage for subcommands. Override in subclass to apply custom formatting.
|
|
376
|
+
*/
|
|
377
|
+
styleSubcommandText(str) {
|
|
378
|
+
return str;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Base style used in terms and usage for commands. Override in subclass to apply custom formatting.
|
|
382
|
+
*/
|
|
383
|
+
styleCommandText(str) {
|
|
384
|
+
return str;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Calculate the pad width from the maximum term length.
|
|
388
|
+
*/
|
|
389
|
+
padWidth(cmd, helper) {
|
|
390
|
+
return Math.max(
|
|
391
|
+
helper.longestOptionTermLength(cmd, helper),
|
|
392
|
+
helper.longestGlobalOptionTermLength(cmd, helper),
|
|
393
|
+
helper.longestSubcommandTermLength(cmd, helper),
|
|
394
|
+
helper.longestArgumentTermLength(cmd, helper)
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Detect manually wrapped and indented strings by checking for line break followed by whitespace.
|
|
399
|
+
*/
|
|
400
|
+
preformatted(str) {
|
|
401
|
+
return /\n[^\S\r\n]/.test(str);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
|
|
405
|
+
*
|
|
406
|
+
* So "TTT", 5, "DDD DDDD DD DDD" might be formatted for this.helpWidth=17 like so:
|
|
407
|
+
* TTT DDD DDDD
|
|
408
|
+
* DD DDD
|
|
409
|
+
*/
|
|
410
|
+
formatItem(term, termWidth, description, helper) {
|
|
411
|
+
const itemIndent = 2;
|
|
412
|
+
const itemIndentStr = " ".repeat(itemIndent);
|
|
413
|
+
if (!description) return itemIndentStr + term;
|
|
414
|
+
const paddedTerm = term.padEnd(termWidth + term.length - helper.displayWidth(term));
|
|
415
|
+
const spacerWidth = 2;
|
|
416
|
+
const helpWidth = this.helpWidth;
|
|
417
|
+
const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
|
|
418
|
+
let formattedDescription;
|
|
419
|
+
if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
|
|
420
|
+
formattedDescription = description;
|
|
421
|
+
} else {
|
|
422
|
+
const wrappedDescription = helper.boxWrap(description, remainingWidth);
|
|
423
|
+
formattedDescription = wrappedDescription.replace(/\n/g, "\n" + " ".repeat(termWidth + spacerWidth));
|
|
424
|
+
}
|
|
425
|
+
return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
|
|
426
|
+
${itemIndentStr}`);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Wrap a string at whitespace, preserving existing line breaks.
|
|
430
|
+
* Wrapping is skipped if the width is less than `minWidthToWrap`.
|
|
431
|
+
*/
|
|
432
|
+
boxWrap(str, width) {
|
|
433
|
+
if (width < this.minWidthToWrap) return str;
|
|
434
|
+
const rawLines = str.split(/\r\n|\n/);
|
|
435
|
+
const chunkPattern = /[\s]*[^\s]+/g;
|
|
436
|
+
const wrappedLines = [];
|
|
437
|
+
rawLines.forEach((line) => {
|
|
438
|
+
const chunks = line.match(chunkPattern);
|
|
439
|
+
if (chunks === null) {
|
|
440
|
+
wrappedLines.push("");
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
let sumChunks = [chunks.shift()];
|
|
444
|
+
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
445
|
+
chunks.forEach((chunk) => {
|
|
446
|
+
const visibleWidth = this.displayWidth(chunk);
|
|
447
|
+
if (sumWidth + visibleWidth <= width) {
|
|
448
|
+
sumChunks.push(chunk);
|
|
449
|
+
sumWidth += visibleWidth;
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
wrappedLines.push(sumChunks.join(""));
|
|
453
|
+
const nextChunk = chunk.trimStart();
|
|
454
|
+
sumChunks = [nextChunk];
|
|
455
|
+
sumWidth = this.displayWidth(nextChunk);
|
|
456
|
+
});
|
|
457
|
+
wrappedLines.push(sumChunks.join(""));
|
|
458
|
+
});
|
|
459
|
+
return wrappedLines.join("\n");
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
__name(_Help, "Help");
|
|
463
|
+
let Help = _Help;
|
|
464
|
+
function stripColor(str) {
|
|
465
|
+
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
466
|
+
return str.replace(sgrPattern, "");
|
|
467
|
+
}
|
|
468
|
+
__name(stripColor, "stripColor");
|
|
469
|
+
function humanReadableArgName(arg) {
|
|
470
|
+
const nameOutput = arg.name + (arg.variadic === true ? "..." : "");
|
|
471
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
472
|
+
}
|
|
473
|
+
__name(humanReadableArgName, "humanReadableArgName");
|
|
474
|
+
export {
|
|
475
|
+
Help
|
|
476
|
+
};
|
|
477
|
+
//# sourceMappingURL=Help.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decorator to make a getter accessor property lazy loaded by setting the property value on the object
|
|
3
|
+
*/
|
|
4
|
+
export default function lazyProp(target: unknown, key: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
5
|
+
//# sourceMappingURL=lazyProp.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
function lazyProp(target, key, descriptor) {
|
|
4
|
+
const orig = descriptor.get;
|
|
5
|
+
if (typeof orig !== "function") {
|
|
6
|
+
throw new Error('"get" not a function');
|
|
7
|
+
}
|
|
8
|
+
descriptor.get = function() {
|
|
9
|
+
const value = orig.call(this);
|
|
10
|
+
Object.defineProperty(this, key, {
|
|
11
|
+
enumerable: false,
|
|
12
|
+
writable: false,
|
|
13
|
+
configurable: true,
|
|
14
|
+
value
|
|
15
|
+
});
|
|
16
|
+
return value;
|
|
17
|
+
};
|
|
18
|
+
return descriptor;
|
|
19
|
+
}
|
|
20
|
+
__name(lazyProp, "lazyProp");
|
|
21
|
+
export {
|
|
22
|
+
lazyProp as default
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=lazyProp.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { Help } from "./Help";
|
|
4
|
+
function renderHelp(cmd, help = new Help()) {
|
|
5
|
+
const helper = Object.assign(help, cmd.helpConfiguration);
|
|
6
|
+
return helper.formatHelp(cmd, helper);
|
|
7
|
+
}
|
|
8
|
+
__name(renderHelp, "renderHelp");
|
|
9
|
+
export {
|
|
10
|
+
renderHelp
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=renderHelp.js.map
|
package/package.json
CHANGED
|
@@ -1,46 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bemoje/cli",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"@bemoje/types": "latest",
|
|
20
|
-
"@commander-js/extra-typings": "^11.1.0",
|
|
21
|
-
"ansi-colors": "^4.1.3",
|
|
22
|
-
"eventemitter3": "^5.0.1",
|
|
23
|
-
"fs-extra": "^11.2.0",
|
|
24
|
-
"is-async-function": "^2.0.0",
|
|
25
|
-
"tslib": "latest"
|
|
3
|
+
"description": "A type-safe CLI builder focused on command composition and help generation without execution coupling. Parse arguments, generate help, and integrate with existing CLI frameworks through a clean, fluent API.",
|
|
4
|
+
"version": "0.3.0",
|
|
5
|
+
"private": false,
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"module": "index.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./lib/index.js",
|
|
11
|
+
"./*": "./lib/*.js",
|
|
12
|
+
"./package.json": "./package.json",
|
|
13
|
+
"./index.d.ts": "./index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"typings": "index.d.ts",
|
|
16
|
+
"dependencies": {},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"commander": "^14.0.0"
|
|
26
19
|
},
|
|
27
20
|
"license": "MIT",
|
|
28
|
-
"
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/bemoje/mono.git"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"cli"
|
|
27
|
+
],
|
|
29
28
|
"author": {
|
|
30
29
|
"name": "Benjamin Møller Jensen",
|
|
31
30
|
"email": "bemoje@bemoje.net",
|
|
32
31
|
"url": "https://github.com/bemoje/"
|
|
33
32
|
},
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
"url": "git+https://github.com/bemoje/tsmono.git"
|
|
37
|
-
},
|
|
38
|
-
"funding": {
|
|
39
|
-
"type": "patreon",
|
|
40
|
-
"url": "https://www.patreon.com/user?u=40752770"
|
|
41
|
-
},
|
|
42
|
-
"bugs": {
|
|
43
|
-
"url": "https://github.com/bemoje/tsmono/issues"
|
|
44
|
-
},
|
|
45
|
-
"homepage": "https://github.com/bemoje/tsmono"
|
|
46
|
-
}
|
|
33
|
+
"homepage": "https://github.com/bemoje/mono"
|
|
34
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Benjamin Møller Jensen
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, 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,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/README.md
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# @bemoje/cli
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-

|
|
7
|
-

|
|
8
|
-

|
|
9
|
-
|
|
10
|
-

|
|
11
|
-

|
|
12
|
-

|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
## Documentation
|
|
16
|
-
[Documentation Website](https://bemoje.github.io/tsmono/modules/cli.html)
|
|
17
|
-
|
|
18
|
-
## Installation
|
|
19
|
-
This library is published in the NPM registry and can be installed using any compatible package manager.
|
|
20
|
-
|
|
21
|
-
#### NPM
|
|
22
|
-
```sh
|
|
23
|
-
npm install @bemoje/cli
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
## Issues
|
|
28
|
-
Please let me know of any bugs or [issues](https://github.com/bemoje/tsmono/issues).
|
|
29
|
-
|
|
30
|
-
## Contribute
|
|
31
|
-
Contributors are welcome to open a [pull request](https://github.com/bemoje/tsmono/pulls).
|
|
32
|
-
|
|
33
|
-
## License
|
|
34
|
-
Released under the [undefined License](./LICENSE).
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Argument } from '@commander-js/extra-typings';
|
|
2
|
-
import { ArgumentParserSelector } from './ArgumentParserSelector';
|
|
3
|
-
import { ArgumentReader } from './ArgumentReader';
|
|
4
|
-
import { ArgumentValidatorSelector } from './ArgumentValidatorSelector';
|
|
5
|
-
import { CommandBuilder } from '../cmd/CommandBuilder';
|
|
6
|
-
/**
|
|
7
|
-
* Wrapper around the @see Argument class from 'commander'.
|
|
8
|
-
*/
|
|
9
|
-
export declare class ArgumentBuilder {
|
|
10
|
-
readonly cmd: CommandBuilder;
|
|
11
|
-
readonly $: Argument;
|
|
12
|
-
readonly index: number;
|
|
13
|
-
constructor(cmd: CommandBuilder, name: string);
|
|
14
|
-
get hasValidators(): boolean;
|
|
15
|
-
get hasParser(): boolean;
|
|
16
|
-
description(...lines: string[]): this;
|
|
17
|
-
default(value: unknown, description?: string): this;
|
|
18
|
-
choices(values: readonly string[]): this;
|
|
19
|
-
get parser(): ArgumentParserSelector;
|
|
20
|
-
get validator(): ArgumentValidatorSelector;
|
|
21
|
-
get get(): ArgumentReader;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=ArgumentBuilder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ArgumentBuilder.d.ts","sourceRoot":"","sources":["../../../../../packages/cli/src/arg/ArgumentBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAGtD;;GAEG;AACH,qBAAa,eAAe;IAId,QAAQ,CAAC,GAAG,EAAE,cAAc;IAHxC,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAA;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;gBAED,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM;IAOtD,IAAI,aAAa,YAEhB;IAED,IAAI,SAAS,YAEZ;IAED,WAAW,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE;IAK9B,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,MAAM;IAK5C,OAAO,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE;IAKjC,IAAI,MAAM,2BAET;IAED,IAAI,SAAS,8BAEZ;IAED,IAAI,GAAG,mBAEN;CACF"}
|