@alcyone-labs/arg-parser 2.14.0 → 2.14.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/dist/index.mjs CHANGED
@@ -5211,6 +5211,10 @@ var PromptManager = class PromptManager {
5211
5211
  return a.index - b.index;
5212
5212
  });
5213
5213
  }
5214
+ static getInitialValue(config, flag) {
5215
+ if (config.initial !== void 0) return config.initial;
5216
+ if ("defaultValue" in flag && flag["defaultValue"] !== void 0) return flag["defaultValue"];
5217
+ }
5214
5218
  async executePrompts(flags) {
5215
5219
  const flagsWithIndex = flags.map((f, index) => ({
5216
5220
  ...f,
@@ -5221,7 +5225,12 @@ var PromptManager = class PromptManager {
5221
5225
  for (const { flag, name } of sortedFlags) try {
5222
5226
  if (!flag.prompt) continue;
5223
5227
  const config = await flag.prompt(this.#context);
5224
- answers[name] = await this.#executePromptWithValidation(name, config);
5228
+ if (config.skip === true) continue;
5229
+ const configWithInitial = {
5230
+ ...config,
5231
+ initial: PromptManager.getInitialValue(config, flag)
5232
+ };
5233
+ answers[name] = await this.#executePromptWithValidation(name, configWithInitial);
5225
5234
  this.#context.promptAnswers = {
5226
5235
  ...this.#context.promptAnswers,
5227
5236
  ...answers
@@ -5279,13 +5288,52 @@ var PromptManager = class PromptManager {
5279
5288
  initialValue: config.initial,
5280
5289
  maxItems: config.maxItems
5281
5290
  });
5282
- case "multiselect": return Lt$1({
5283
- message: config.message,
5284
- options: this.#normalizeOptions(config.options ?? []),
5285
- initialValues: config.initial,
5291
+ case "multiselect":
5292
+ if (config.allowSelectAll) return this.#executeMultiselectWithSelectAll(config);
5293
+ return Lt$1({
5294
+ message: config.message,
5295
+ options: this.#normalizeOptions(config.options ?? []),
5296
+ initialValues: config.initial,
5297
+ maxItems: config.maxItems
5298
+ });
5299
+ default: throw new Error(`Unknown prompt type: ${config.type}`);
5300
+ }
5301
+ }
5302
+ async #executeMultiselectWithSelectAll(config) {
5303
+ const options = this.#normalizeOptions(config.options ?? []);
5304
+ const allValues = options.map((opt) => opt.value);
5305
+ let selectedValues = Array.isArray(config.initial) ? [...config.initial] : [];
5306
+ R.info("Press 'a' to select/deselect all options");
5307
+ while (true) {
5308
+ const result = await Lt$1({
5309
+ message: `${config.message} (press 'a' to toggle all)`,
5310
+ options: options.map((opt) => ({ ...opt })),
5311
+ initialValues: selectedValues,
5286
5312
  maxItems: config.maxItems
5287
5313
  });
5288
- default: throw new Error(`Unknown prompt type: ${config.type}`);
5314
+ if (Ct(result)) return result;
5315
+ if (result.length === 0 || result.length < allValues.length && result.length > 0) {
5316
+ const toggleAll = await Mt$1({
5317
+ message: "Select all options?",
5318
+ initialValue: false
5319
+ });
5320
+ if (Ct(toggleAll)) return result;
5321
+ if (toggleAll) {
5322
+ selectedValues = [...allValues];
5323
+ continue;
5324
+ }
5325
+ } else if (result.length === allValues.length) {
5326
+ const deselectAll = await Mt$1({
5327
+ message: "Deselect all options?",
5328
+ initialValue: false
5329
+ });
5330
+ if (Ct(deselectAll)) return result;
5331
+ if (deselectAll) {
5332
+ selectedValues = [];
5333
+ continue;
5334
+ }
5335
+ }
5336
+ return result;
5289
5337
  }
5290
5338
  }
5291
5339
  #normalizeOptions(options) {