@guanzhu.me/pw-cli 0.0.16 → 0.0.17

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/bin/pw-cli.js +64 -0
  2. package/package.json +9 -1
package/bin/pw-cli.js CHANGED
@@ -305,6 +305,68 @@ Example:
305
305
  `;
306
306
  }
307
307
 
308
+ const REQUIRED_POSITIONAL_ARGS = new Map([
309
+ ['goto', { count: 1, usage: 'pw-cli goto <url>' }],
310
+ ['type', { count: 1, usage: 'pw-cli type <text>' }],
311
+ ['click', { count: 1, usage: 'pw-cli click <ref> [button]' }],
312
+ ['dblclick', { count: 1, usage: 'pw-cli dblclick <ref> [button]' }],
313
+ ['fill', { count: 2, usage: 'pw-cli fill <ref> <text>' }],
314
+ ['drag', { count: 2, usage: 'pw-cli drag <startRef> <endRef>' }],
315
+ ['hover', { count: 1, usage: 'pw-cli hover <ref>' }],
316
+ ['select', { count: 2, usage: 'pw-cli select <ref> <value>' }],
317
+ ['upload', { count: 1, usage: 'pw-cli upload <file>' }],
318
+ ['check', { count: 1, usage: 'pw-cli check <ref>' }],
319
+ ['uncheck', { count: 1, usage: 'pw-cli uncheck <ref>' }],
320
+ ['eval', { count: 1, usage: 'pw-cli eval <func> [ref]' }],
321
+ ['resize', { count: 2, usage: 'pw-cli resize <width> <height>' }],
322
+ ['press', { count: 1, usage: 'pw-cli press <key>' }],
323
+ ['keydown', { count: 1, usage: 'pw-cli keydown <key>' }],
324
+ ['keyup', { count: 1, usage: 'pw-cli keyup <key>' }],
325
+ ['mousemove', { count: 2, usage: 'pw-cli mousemove <x> <y>' }],
326
+ ['mousewheel', { count: 2, usage: 'pw-cli mousewheel <dx> <dy>' }],
327
+ ['tab-select', { count: 1, usage: 'pw-cli tab-select <index>' }],
328
+ ['cookie-get', { count: 1, usage: 'pw-cli cookie-get <name>' }],
329
+ ['cookie-set', { count: 2, usage: 'pw-cli cookie-set <name> <value>' }],
330
+ ['cookie-delete', { count: 1, usage: 'pw-cli cookie-delete <name>' }],
331
+ ['localstorage-get', { count: 1, usage: 'pw-cli localstorage-get <key>' }],
332
+ ['localstorage-set', { count: 2, usage: 'pw-cli localstorage-set <key> <value>' }],
333
+ ['localstorage-delete', { count: 1, usage: 'pw-cli localstorage-delete <key>' }],
334
+ ['sessionstorage-get', { count: 1, usage: 'pw-cli sessionstorage-get <key>' }],
335
+ ['sessionstorage-set', { count: 2, usage: 'pw-cli sessionstorage-set <key> <value>' }],
336
+ ['sessionstorage-delete', { count: 1, usage: 'pw-cli sessionstorage-delete <key>' }],
337
+ ['route', { count: 1, usage: 'pw-cli route <pattern>' }],
338
+ ]);
339
+
340
+ function getPositionalsAfterCommand(argv, command) {
341
+ const commandIdx = argv.indexOf(command);
342
+ if (commandIdx === -1) return [];
343
+
344
+ const positionals = [];
345
+ for (let i = commandIdx + 1; i < argv.length; i++) {
346
+ const arg = argv[i];
347
+ if (typeof arg !== 'string' || arg.length === 0) continue;
348
+ if (arg === '--') {
349
+ positionals.push(...argv.slice(i + 1).filter(Boolean));
350
+ break;
351
+ }
352
+ if (!arg.startsWith('-')) {
353
+ positionals.push(arg);
354
+ }
355
+ }
356
+ return positionals;
357
+ }
358
+
359
+ function validateRequiredArgs(argv, command) {
360
+ const rule = REQUIRED_POSITIONAL_ARGS.get(command);
361
+ if (!rule) return;
362
+
363
+ const positionals = getPositionalsAfterCommand(argv, command);
364
+ if (positionals.length >= rule.count) return;
365
+
366
+ process.stderr.write(`pw-cli: ${command} requires ${rule.count === 1 ? 'an argument' : `${rule.count} arguments`}\n\nUsage: ${rule.usage}\n`);
367
+ process.exit(1);
368
+ }
369
+
308
370
  // Management commands that don't need a running browser
309
371
  const MGMT_COMMANDS = new Set([
310
372
  'open', 'close', 'list', 'kill-all', 'close-all', 'delete-data',
@@ -753,6 +815,8 @@ async function main() {
753
815
  process.exit(1);
754
816
  }
755
817
 
818
+ validateRequiredArgs(rawArgv, command);
819
+
756
820
  // ── queue: batch actions and run them together ────────────────────────────
757
821
  if (command === 'queue') {
758
822
  await handleQueue(rawArgv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guanzhu.me/pw-cli",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "Persistent Playwright browser CLI with headed defaults, profile support, queueing, and script execution",
5
5
  "bin": {
6
6
  "pw-cli": "./bin/pw-cli.js"
@@ -34,5 +34,13 @@
34
34
  "chromium",
35
35
  "testing"
36
36
  ],
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/wn0x00/pw-cli.git"
40
+ },
41
+ "homepage": "https://github.com/wn0x00/pw-cli#readme",
42
+ "bugs": {
43
+ "url": "https://github.com/wn0x00/pw-cli/issues"
44
+ },
37
45
  "license": "MIT"
38
46
  }