@dashai/cli 0.18.0 → 0.18.2

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/bin.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
+ import pc from 'picocolors';
2
3
  import { existsSync, readFileSync, writeFileSync, rmSync, mkdirSync, watch, readdirSync, chmodSync, renameSync, mkdtempSync, statSync } from 'fs';
3
4
  import { tmpdir, platform, homedir } from 'os';
4
5
  import { resolve, join, relative, dirname, basename, sep } from 'path';
5
- import pc from 'picocolors';
6
6
  import { spawn, spawnSync } from 'child_process';
7
7
  import { intro, log, select, isCancel, cancel, spinner, outro, text, multiselect, confirm } from '@clack/prompts';
8
8
  import { Command, Option } from 'commander';
@@ -20,6 +20,41 @@ var __export = (target, all) => {
20
20
  for (var name in all)
21
21
  __defProp(target, name, { get: all[name], enumerable: true });
22
22
  };
23
+ function success(msg) {
24
+ process.stderr.write(`${pc.green("\u2713")} ${msg}
25
+ `);
26
+ }
27
+ function info(msg) {
28
+ process.stderr.write(`${pc.cyan("\u2139")} ${msg}
29
+ `);
30
+ }
31
+ function warn(msg) {
32
+ process.stderr.write(`${pc.yellow("\u26A0")} ${msg}
33
+ `);
34
+ }
35
+ function fail(msg) {
36
+ process.stderr.write(`${pc.red("\u2717")} ${msg}
37
+ `);
38
+ }
39
+ function out(msg) {
40
+ process.stdout.write(`${msg}
41
+ `);
42
+ }
43
+ function kv(key, value, padTo = 14) {
44
+ const padded = key.padEnd(padTo);
45
+ process.stdout.write(`${pc.bold(padded)} ${value}
46
+ `);
47
+ }
48
+ function code(s) {
49
+ return pc.cyan(s);
50
+ }
51
+ function dim(s) {
52
+ return pc.dim(s);
53
+ }
54
+ var init_output = __esm({
55
+ "src/lib/output.ts"() {
56
+ }
57
+ });
23
58
  function configDir() {
24
59
  if (process.env.XDG_CONFIG_HOME) {
25
60
  return join(process.env.XDG_CONFIG_HOME, DIR_NAME);
@@ -499,41 +534,6 @@ var init_api_client = __esm({
499
534
  };
500
535
  }
501
536
  });
502
- function success(msg) {
503
- process.stderr.write(`${pc.green("\u2713")} ${msg}
504
- `);
505
- }
506
- function info(msg) {
507
- process.stderr.write(`${pc.cyan("\u2139")} ${msg}
508
- `);
509
- }
510
- function warn(msg) {
511
- process.stderr.write(`${pc.yellow("\u26A0")} ${msg}
512
- `);
513
- }
514
- function fail(msg) {
515
- process.stderr.write(`${pc.red("\u2717")} ${msg}
516
- `);
517
- }
518
- function out(msg) {
519
- process.stdout.write(`${msg}
520
- `);
521
- }
522
- function kv(key, value, padTo = 14) {
523
- const padded = key.padEnd(padTo);
524
- process.stdout.write(`${pc.bold(padded)} ${value}
525
- `);
526
- }
527
- function code(s) {
528
- return pc.cyan(s);
529
- }
530
- function dim(s) {
531
- return pc.dim(s);
532
- }
533
- var init_output = __esm({
534
- "src/lib/output.ts"() {
535
- }
536
- });
537
537
 
538
538
  // src/lib/connect-status.ts
539
539
  async function reportConnectStatus(opts) {
@@ -5278,7 +5278,81 @@ var init_set_type = __esm({
5278
5278
  }
5279
5279
  });
5280
5280
 
5281
+ // src/lib/excess-args.ts
5282
+ init_output();
5283
+ var SMART_DASH_RE = /^[‒–—―−]/;
5284
+ var ExcessArgumentsError = class extends Error {
5285
+ constructor(message) {
5286
+ super(message);
5287
+ this.name = "ExcessArgumentsError";
5288
+ }
5289
+ };
5290
+ function commandPath(cmd) {
5291
+ const parts = [];
5292
+ let cursor = cmd;
5293
+ while (cursor) {
5294
+ parts.unshift(cursor.name());
5295
+ cursor = cursor.parent;
5296
+ }
5297
+ return parts.join(" ");
5298
+ }
5299
+ function excessOperandsError(actionCommand) {
5300
+ const registered = actionCommand.registeredArguments;
5301
+ if (registered.length > 0 && registered[registered.length - 1].variadic) {
5302
+ return null;
5303
+ }
5304
+ const operands = actionCommand.args;
5305
+ const stray = operands.slice(registered.length);
5306
+ const accepted = operands.slice(0, registered.length);
5307
+ const smartDashAccepted = accepted.filter((s) => SMART_DASH_RE.test(s));
5308
+ if (stray.length === 0 && smartDashAccepted.length === 0) return null;
5309
+ const path = commandPath(actionCommand);
5310
+ const expects = registered.length === 0 ? "takes no positional arguments" : `takes at most ${registered.length} positional argument${registered.length > 1 ? "s" : ""} (${registered.map((a) => `${a.required ? "<" : "["}${a.name()}${a.required ? ">" : "]"}`).join(" ")})`;
5311
+ const lines = [];
5312
+ if (stray.length > 0) {
5313
+ lines.push(
5314
+ `Unexpected argument${stray.length > 1 ? "s" : ""} ${stray.map((s) => `"${s}"`).join(", ")} \u2014 ${code(path)} ${expects}.`
5315
+ );
5316
+ }
5317
+ for (const tok of smartDashAccepted) {
5318
+ const slot = registered[accepted.indexOf(tok)];
5319
+ lines.push(
5320
+ `"${tok}" was read as the ${slot ? `<${slot.name()}>` : "positional"} argument but looks like a flag typed with a typographic dash (\u2013 / \u2014) instead of ASCII "--".`
5321
+ );
5322
+ }
5323
+ if ([...stray, ...smartDashAccepted].some((s) => SMART_DASH_RE.test(s))) {
5324
+ lines.push(
5325
+ `A token starts with a typographic dash (\u2013 / \u2014) instead of ASCII "--". If this command was copy-pasted, the editor/chat likely rewrote the double hyphen \u2014 retype the flag by hand (e.g. ${code("--force")}, ${code("--grant")}).`
5326
+ );
5327
+ }
5328
+ if (stray.some((s) => /^(module|datahub):/.test(s)) && actionCommand.options.some((o) => o.long === "--grant")) {
5329
+ lines.push(
5330
+ `Grant specs must be passed via the (repeatable) ${code("--grant")} flag, e.g. ${code("--grant module:employees:create,read")}.`
5331
+ );
5332
+ }
5333
+ if (stray.some((s) => s.startsWith("--"))) {
5334
+ lines.push(
5335
+ `Tokens after a bare ${code("--")} separator are treated as plain arguments, not flags \u2014 remove the ${code("--")}.`
5336
+ );
5337
+ }
5338
+ lines.push(
5339
+ "Refusing to continue: silently ignoring these arguments is how grantless (deny-all) API keys \u2014 or half-applied commands \u2014 happen by accident."
5340
+ );
5341
+ return lines.join("\n ");
5342
+ }
5343
+ function installExcessArgumentsGuard(program2) {
5344
+ program2.hook("preAction", (_thisCommand, actionCommand) => {
5345
+ const message = excessOperandsError(actionCommand);
5346
+ if (message === null) return;
5347
+ fail(message);
5348
+ throw new ExcessArgumentsError(message);
5349
+ });
5350
+ }
5351
+
5281
5352
  // src/bin.ts
5353
+ init_output();
5354
+
5355
+ // src/program.ts
5282
5356
  init_dev();
5283
5357
 
5284
5358
  // src/commands/login.ts
@@ -6676,7 +6750,7 @@ async function moduleDiffCommand(options) {
6676
6750
  return 0;
6677
6751
  }
6678
6752
 
6679
- // src/bin.ts
6753
+ // src/program.ts
6680
6754
  init_init();
6681
6755
 
6682
6756
  // src/commands/module/install.ts
@@ -9714,7 +9788,7 @@ function surfacePullFailure(err) {
9714
9788
  return 1;
9715
9789
  }
9716
9790
 
9717
- // src/bin.ts
9791
+ // src/program.ts
9718
9792
  init_scaffold();
9719
9793
 
9720
9794
  // src/commands/api-keys.ts
@@ -11374,7 +11448,7 @@ async function sleep4(ms, aborted) {
11374
11448
  }
11375
11449
  }
11376
11450
 
11377
- // src/bin.ts
11451
+ // src/program.ts
11378
11452
  init_output();
11379
11453
  var program = new Command();
11380
11454
  program.name("dashwise").description("DashWise CLI \u2014 log in, author modules, publish to the marketplace.").version(getVersion(), "-v, --version", "Show the CLI version + exit").option(
@@ -11387,6 +11461,7 @@ program.hook("preAction", () => {
11387
11461
  process.env.DASHWISE_API_URL = apiUrl.replace(/\/+$/, "");
11388
11462
  }
11389
11463
  });
11464
+ installExcessArgumentsGuard(program);
11390
11465
  program.command("login").description("Sign in via the device-code flow.").option("--no-prompt", 'Skip the "open browser" prompt; just print the URL.').option("--name <name>", "Suggested name for the minted token (default: dashwise-cli).").action(async (cmdOpts) => {
11391
11466
  const apiUrl = program.opts().apiUrl;
11392
11467
  const exit = await loginCommand({
@@ -11760,14 +11835,16 @@ apiKeysCmd.command("list").description(
11760
11835
  "--install <id>",
11761
11836
  "Target a specific installation id instead of the cached dev install (production installs included). Find ids via `dashwise module status <slug>`.",
11762
11837
  parseIntOption
11763
- ).option("--all", "Include revoked + expired keys in the output.").option("--json", "Emit JSON instead of the human-friendly table.").action(async (cmdOpts) => {
11764
- process.exitCode = await apiKeysListCommand({
11765
- ...cmdOpts.dir !== void 0 ? { dir: cmdOpts.dir } : {},
11766
- ...cmdOpts.install !== void 0 ? { install: cmdOpts.install } : {},
11767
- ...cmdOpts.all !== void 0 ? { all: cmdOpts.all } : {},
11768
- ...cmdOpts.json !== void 0 ? { json: cmdOpts.json } : {}
11769
- });
11770
- });
11838
+ ).option("--all", "Include revoked + expired keys in the output.").option("--json", "Emit JSON instead of the human-friendly table.").action(
11839
+ async (cmdOpts) => {
11840
+ process.exitCode = await apiKeysListCommand({
11841
+ ...cmdOpts.dir !== void 0 ? { dir: cmdOpts.dir } : {},
11842
+ ...cmdOpts.install !== void 0 ? { install: cmdOpts.install } : {},
11843
+ ...cmdOpts.all !== void 0 ? { all: cmdOpts.all } : {},
11844
+ ...cmdOpts.json !== void 0 ? { json: cmdOpts.json } : {}
11845
+ });
11846
+ }
11847
+ );
11771
11848
  apiKeysCmd.command("create [name]").description(
11772
11849
  "Mint a new API key. The plaintext key is displayed ONCE \u2014 save it then."
11773
11850
  ).option("--dir <path>", "Project root (default: current directory).").option(
@@ -12148,19 +12225,8 @@ fieldCmd.command("set-type <table-slug> <field-slug> <new-type>").description(
12148
12225
  );
12149
12226
  }
12150
12227
  );
12151
- (async () => {
12152
- try {
12153
- await program.parseAsync(process.argv);
12154
- } catch (err) {
12155
- fail(`Unhandled error: ${err.message ?? String(err)}`);
12156
- if (process.env.DASHWISE_DEBUG) {
12157
- console.error(err);
12158
- }
12159
- process.exitCode = 1;
12160
- }
12161
- })();
12162
12228
  function getVersion() {
12163
- return "0.18.0";
12229
+ return "0.18.2";
12164
12230
  }
12165
12231
  function parseIntOption(value) {
12166
12232
  const n = Number.parseInt(value, 10);
@@ -12172,5 +12238,22 @@ function parseIntOption(value) {
12172
12238
  function collectRepeated(value, previous) {
12173
12239
  return [...previous, value];
12174
12240
  }
12241
+
12242
+ // src/bin.ts
12243
+ (async () => {
12244
+ try {
12245
+ await program.parseAsync(process.argv);
12246
+ } catch (err) {
12247
+ if (err instanceof ExcessArgumentsError) {
12248
+ process.exitCode = 1;
12249
+ return;
12250
+ }
12251
+ fail(`Unhandled error: ${err.message ?? String(err)}`);
12252
+ if (process.env.DASHWISE_DEBUG) {
12253
+ console.error(err);
12254
+ }
12255
+ process.exitCode = 1;
12256
+ }
12257
+ })();
12175
12258
  //# sourceMappingURL=bin.js.map
12176
12259
  //# sourceMappingURL=bin.js.map