@swmansion/argent 0.18.1-next.13 → 0.18.1-next.15

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.
Files changed (2) hide show
  1. package/dist/cli-cmds.mjs +106 -15
  2. package/package.json +1 -1
package/dist/cli-cmds.mjs CHANGED
@@ -1304,15 +1304,20 @@ function setAtPath(obj, dottedKey, value) {
1304
1304
  }
1305
1305
  function deleteAtPath(obj, dottedKey) {
1306
1306
  const parts = splitKey(dottedKey);
1307
- let cur = obj;
1307
+ const chain = [obj];
1308
1308
  for (let i2 = 0; i2 < parts.length - 1; i2++) {
1309
- const next = cur[parts[i2]];
1309
+ const next = chain[i2][parts[i2]];
1310
1310
  if (!isPlainObject(next)) return false;
1311
- cur = next;
1311
+ chain.push(next);
1312
1312
  }
1313
+ const parent = chain[parts.length - 1];
1313
1314
  const leaf = parts[parts.length - 1];
1314
- if (!Object.hasOwn(cur, leaf)) return false;
1315
- delete cur[leaf];
1315
+ if (!Object.hasOwn(parent, leaf)) return false;
1316
+ delete parent[leaf];
1317
+ for (let i2 = chain.length - 1; i2 >= 1; i2--) {
1318
+ if (Object.keys(chain[i2]).length > 0) break;
1319
+ delete chain[i2 - 1][parts[i2 - 1]];
1320
+ }
1316
1321
  return true;
1317
1322
  }
1318
1323
  var LOCK_STALE_MS2 = 1e4;
@@ -1447,6 +1452,9 @@ function asString(raw) {
1447
1452
  const trimmed = raw.trim();
1448
1453
  return trimmed === "" ? void 0 : trimmed;
1449
1454
  }
1455
+ function asNumber(raw) {
1456
+ return typeof raw === "number" && Number.isFinite(raw) ? raw : void 0;
1457
+ }
1450
1458
  function asStringArray(raw) {
1451
1459
  if (!Array.isArray(raw)) return void 0;
1452
1460
  const out = [];
@@ -1455,6 +1463,15 @@ function asStringArray(raw) {
1455
1463
  }
1456
1464
  return out;
1457
1465
  }
1466
+ var PARSER_EXPECTATIONS = /* @__PURE__ */ new Map([
1467
+ [asBoolean, "a boolean (true or false)"],
1468
+ [asString, "a non-empty string"],
1469
+ [asNumber, "a number"],
1470
+ [asStringArray, "an array of strings"]
1471
+ ]);
1472
+ function describeExpectedValue(def) {
1473
+ return def.expected ?? PARSER_EXPECTATIONS.get(def.parse);
1474
+ }
1458
1475
  var CONFIG_SCHEMA = [
1459
1476
  {
1460
1477
  key: "telemetry.enabled",
@@ -1560,12 +1577,18 @@ var ConfigScopeError = class extends Error {
1560
1577
  allowed;
1561
1578
  };
1562
1579
  var ConfigValidationError = class extends Error {
1563
- constructor(key) {
1564
- super(`Invalid value for config key "${key}".`);
1580
+ constructor(key, expected, example) {
1581
+ super(
1582
+ expected ? `Invalid value for config key "${key}": expected ${expected}.` : `Invalid value for config key "${key}".`
1583
+ );
1565
1584
  this.key = key;
1585
+ this.expected = expected;
1586
+ this.example = example;
1566
1587
  this.name = "ConfigValidationError";
1567
1588
  }
1568
1589
  key;
1590
+ expected;
1591
+ example;
1569
1592
  };
1570
1593
  var ConfigManagedElsewhereError = class extends Error {
1571
1594
  constructor(key, command) {
@@ -1582,7 +1605,8 @@ function setConfigValue(key, rawValue, scope = "global", options = {}, registry
1582
1605
  if (def.manageCommand) throw new ConfigManagedElsewhereError(key, def.manageCommand);
1583
1606
  if (!def.scopes.includes(scope)) throw new ConfigScopeError(key, scope, def.scopes);
1584
1607
  const parsed = def.parse(rawValue);
1585
- if (parsed === void 0) throw new ConfigValidationError(key);
1608
+ if (parsed === void 0)
1609
+ throw new ConfigValidationError(def.key, describeExpectedValue(def), def.example);
1586
1610
  updateConfig((config2) => setAtPath(config2, key, parsed), scope, options);
1587
1611
  return parsed;
1588
1612
  }
@@ -1607,6 +1631,8 @@ function listConfig(options = {}, registry = CONFIG_SCHEMA) {
1607
1631
  description: def.description,
1608
1632
  scopes: def.scopes,
1609
1633
  ...def.manageCommand ? { manageCommand: def.manageCommand } : {},
1634
+ ...describeExpectedValue(def) ? { expected: describeExpectedValue(def) } : {},
1635
+ ...def.example ? { example: def.example } : {},
1610
1636
  effective: getConfigValue(def, options),
1611
1637
  project: readScopeValue(def, "project", options),
1612
1638
  global: readScopeValue(def, "global", options)
@@ -8465,6 +8491,12 @@ function isJsonField(prop) {
8465
8491
  function flagNameFor(name, prop) {
8466
8492
  return isJsonField(prop) ? `--${name}-json` : `--${name}`;
8467
8493
  }
8494
+ function booleanLiteral(raw) {
8495
+ const value = raw.trim().toLowerCase();
8496
+ if (value === "true" || value === "1") return true;
8497
+ if (value === "false" || value === "0") return false;
8498
+ return void 0;
8499
+ }
8468
8500
  function coerceScalar(raw, type, field) {
8469
8501
  if (type === "number") {
8470
8502
  if (raw.trim() === "")
@@ -8482,9 +8514,9 @@ function coerceScalar(raw, type, field) {
8482
8514
  return n2;
8483
8515
  }
8484
8516
  if (type === "boolean") {
8485
- if (raw === "true" || raw === "1") return true;
8486
- if (raw === "false" || raw === "0") return false;
8487
- throw new FlagParseException(`--${field} expected true/false, got "${raw}"`);
8517
+ const value = booleanLiteral(raw);
8518
+ if (value !== void 0) return value;
8519
+ throw new FlagParseException(`--${field} expected true/false (or 1/0), got "${raw}"`);
8488
8520
  }
8489
8521
  return raw;
8490
8522
  }
@@ -8561,6 +8593,12 @@ function parseFlags(argv, schema) {
8561
8593
  if (inlineValue !== void 0) {
8562
8594
  throw new FlagParseException(`--no-${fieldName} does not take a value`);
8563
8595
  }
8596
+ const following = i2 + 1 < argv.length ? booleanLiteral(argv[i2 + 1]) : void 0;
8597
+ if (following !== void 0) {
8598
+ throw new FlagParseException(
8599
+ `--no-${fieldName} does not take a value; use --${fieldName} ${following}`
8600
+ );
8601
+ }
8564
8602
  args[fieldName] = false;
8565
8603
  continue;
8566
8604
  }
@@ -8569,6 +8607,12 @@ function parseFlags(argv, schema) {
8569
8607
  if (propSchema?.type === "boolean") {
8570
8608
  if (inlineValue !== void 0) {
8571
8609
  args[flag] = coerceScalar(inlineValue, "boolean", flag);
8610
+ continue;
8611
+ }
8612
+ const next = i2 + 1 < argv.length ? booleanLiteral(argv[i2 + 1]) : void 0;
8613
+ if (next !== void 0) {
8614
+ args[flag] = next;
8615
+ i2 += 1;
8572
8616
  } else {
8573
8617
  args[flag] = true;
8574
8618
  }
@@ -8626,6 +8670,12 @@ function formatSchemaUsage(schema) {
8626
8670
  const desc = prop.description ? ` ${prop.description}` : "";
8627
8671
  lines.push(` ${flag} ${typeLabel}${req}${desc}`);
8628
8672
  }
8673
+ if (entries.some(([, prop]) => prop.type === "boolean")) {
8674
+ lines.push(
8675
+ "",
8676
+ " Booleans: --flag, --flag true, or --flag 1 sets true; --flag false, --flag 0, --flag=false, or --no-flag sets false."
8677
+ );
8678
+ }
8629
8679
  return lines.join("\n");
8630
8680
  }
8631
8681
  function renderFlagName(name, prop) {
@@ -8924,6 +8974,11 @@ Examples:
8924
8974
  printToolHelp(meta);
8925
8975
  return;
8926
8976
  }
8977
+ if (parsed.positional.length > 0) {
8978
+ console.error(
8979
+ `Note: ignoring unused argument(s): ${parsed.positional.join(", ")}. Pass values as --flag <value> or --flag=<value>.`
8980
+ );
8981
+ }
8927
8982
  let payload = {};
8928
8983
  if (parsed.rawArgs !== null) {
8929
8984
  let rawJson = parsed.rawArgs;
@@ -9081,6 +9136,12 @@ function parseRunArgs(argv) {
9081
9136
  };
9082
9137
  const noValue = (name) => {
9083
9138
  if (inline !== void 0) throw new FlagParseException(`${name} does not take a value`);
9139
+ const next = argv[i2 + 1]?.trim().toLowerCase();
9140
+ if (next === "true" || next === "false") {
9141
+ throw new FlagParseException(
9142
+ `${name} does not take a value \u2014 it is a switch; omit it to leave the option off`
9143
+ );
9144
+ }
9084
9145
  };
9085
9146
  if (flag === "--update-baselines") {
9086
9147
  noValue("--update-baselines");
@@ -10451,8 +10512,15 @@ function parseArgs(argv) {
10451
10512
  for (let i2 = 0; i2 < argv.length; i2++) {
10452
10513
  const tok = argv[i2];
10453
10514
  if (tok === "--help" || tok === "-h") help = true;
10454
- else if (tok === "--forget") forget = true;
10455
- else if (tok === "--terminal" || tok === "-t") {
10515
+ else if (tok === "--forget") {
10516
+ forget = true;
10517
+ const next = argv[i2 + 1]?.trim().toLowerCase();
10518
+ if (next === "true" || next === "false") {
10519
+ process.stderr.write(`lens: --forget does not take a value; omit it to keep the state
10520
+ `);
10521
+ process.exit(2);
10522
+ }
10523
+ } else if (tok === "--terminal" || tok === "-t") {
10456
10524
  const v = argv[++i2];
10457
10525
  if (v === "iterm" || v === "terminal") terminal = v;
10458
10526
  else {
@@ -11013,6 +11081,7 @@ the raw value stored at each scope.`);
11013
11081
  }
11014
11082
  function scopeDetail(e) {
11015
11083
  const parts = [`scopes: ${e.scopes.join(", ")}`];
11084
+ if (e.expected) parts.push(`value: ${e.expected}${e.example ? `, e.g. ${e.example}` : ""}`);
11016
11085
  if (e.project !== void 0) parts.push(`project=${formatValuePlain(e.project)}`);
11017
11086
  if (e.global !== void 0) parts.push(`global=${formatValuePlain(e.global)}`);
11018
11087
  return parts.join(" \xB7 ");
@@ -11077,7 +11146,7 @@ parsed (e.g. \`true\`, \`42\`, \`["a","b"]\`); anything else is stored as a stri
11077
11146
  if (warning) console.error(import_picocolors2.default.yellow(warning));
11078
11147
  console.log(`Set ${import_picocolors2.default.bold(key)} = ${formatValuePlain(stored)} (${scopeLabel(targetScope)}).`);
11079
11148
  } catch (err) {
11080
- reportError(err);
11149
+ reportError(err, () => suggestCorrectedSet(err, key, rawValue, scope));
11081
11150
  }
11082
11151
  }
11083
11152
  function cmdUnset(argv) {
@@ -11170,7 +11239,20 @@ function formatValue(value) {
11170
11239
  }
11171
11240
  return formatValuePlain(value);
11172
11241
  }
11173
- function reportError(err) {
11242
+ function quoteForShell(value) {
11243
+ if (/^[A-Za-z0-9._/@:+-]+$/.test(value)) return value;
11244
+ return `'${value.replace(/'/g, `'\\''`)}'`;
11245
+ }
11246
+ function suggestCorrectedSet(err, key, rawValue, scope) {
11247
+ if (!(err instanceof ConfigValidationError)) return null;
11248
+ const def = getConfigDefinition(key);
11249
+ if (!def) return null;
11250
+ const wrapped = def.parse([rawValue]);
11251
+ if (wrapped === void 0) return null;
11252
+ const scopeFlag = scope ? ` --scope ${scope}` : "";
11253
+ return `argent config set ${key} ${quoteForShell(JSON.stringify([rawValue]))}${scopeFlag}`;
11254
+ }
11255
+ function reportError(err, suggest) {
11174
11256
  if (err instanceof ConfigManagedElsewhereError) {
11175
11257
  console.error(`Error: ${err.message} Use \`${err.command}\` instead.`);
11176
11258
  } else if (err instanceof UnknownConfigKeyError || err instanceof ConfigScopeError || err instanceof ConfigValidationError) {
@@ -11178,6 +11260,15 @@ function reportError(err) {
11178
11260
  if (err instanceof UnknownConfigKeyError) {
11179
11261
  console.error(`Run \`argent config list\` to see available keys.`);
11180
11262
  }
11263
+ if (err instanceof ConfigValidationError) {
11264
+ const corrected = suggest?.() ?? null;
11265
+ if (corrected) {
11266
+ console.error(`Did you mean: ${corrected}`);
11267
+ } else if (err.example) {
11268
+ console.error(`Example: argent config set ${err.key} ${quoteForShell(err.example)}`);
11269
+ }
11270
+ console.error(`Run \`argent config list\` to see each key's expected value.`);
11271
+ }
11181
11272
  } else {
11182
11273
  console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
11183
11274
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swmansion/argent",
3
- "version": "0.18.1-next.13",
3
+ "version": "0.18.1-next.15",
4
4
  "mcpName": "io.github.software-mansion/argent",
5
5
  "description": "MCP server for iOS Simulator and Android Emulator control",
6
6
  "license": "Apache-2.0",