@leeguoo/wrangler-accounts 0.1.3 → 0.1.5

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/README.md CHANGED
@@ -45,7 +45,8 @@ wrangler-accounts remove old
45
45
  ```text
46
46
  -c, --config <path> Wrangler config path
47
47
  -p, --profiles <path> Profiles directory
48
- --json JSON output for list/status
48
+ --json JSON output for all commands
49
+ --plain Plain output for list (one name per line)
49
50
  -f, --force Overwrite existing profile on save
50
51
  --backup Backup current config on use (default)
51
52
  --no-backup Disable backup on use
@@ -57,6 +58,18 @@ wrangler-accounts remove old
57
58
  - WRANGLER_ACCOUNTS_DIR
58
59
  - XDG_CONFIG_HOME
59
60
 
61
+ ## JSON output
62
+
63
+ Use `--json` for machine-readable output.
64
+
65
+ Examples:
66
+
67
+ ```bash
68
+ wrangler-accounts list --json
69
+ wrangler-accounts status --json
70
+ wrangler-accounts use personal --json
71
+ ```
72
+
60
73
  ## Defaults
61
74
 
62
75
  If you do not specify a config path, the CLI checks for these and uses the first existing path:
@@ -76,3 +89,22 @@ The profiles directory defaults to:
76
89
  - Profile names accept only letters, numbers, dot, underscore, and dash.
77
90
  - On `use`, the current config is backed up into `__backup-YYYYMMDD-HHMMSS` unless you pass `--no-backup`.
78
91
  - `login <name>` overwrites an existing profile with the same name.
92
+
93
+ ## Discoverability (SEO / GEO / AI search)
94
+
95
+ This project is a Cloudflare Wrangler multi-account switcher for global teams.
96
+ Keywords: Cloudflare Workers account manager, Wrangler login profiles, multi-account, account switcher, geo-distributed ops, AI search indexing.
97
+
98
+ ## Shell completion (zsh)
99
+
100
+ ```bash
101
+ mkdir -p ~/.zsh/completions
102
+ cp $(pnpm root -g)/@leeguoo/wrangler-accounts/completions/wrangler-accounts.zsh ~/.zsh/completions/_wrangler-accounts
103
+ ```
104
+
105
+ Then add to your `~/.zshrc`:
106
+
107
+ ```bash
108
+ fpath=(~/.zsh/completions $fpath)
109
+ autoload -Uz compinit && compinit
110
+ ```
@@ -7,9 +7,15 @@ const os = require("os");
7
7
  const crypto = require("crypto");
8
8
  const { spawnSync } = require("child_process");
9
9
 
10
- function die(message) {
11
- console.error(`Error: ${message}`);
12
- process.exit(1);
10
+ let outputJson = false;
11
+
12
+ function die(message, exitCode = 1) {
13
+ if (outputJson) {
14
+ console.error(JSON.stringify({ error: message }, null, 2));
15
+ } else {
16
+ console.error(`Error: ${message}`);
17
+ }
18
+ process.exit(exitCode);
13
19
  }
14
20
 
15
21
  function printHelp(exitCode = 0) {
@@ -29,7 +35,8 @@ Commands:
29
35
  Options:
30
36
  -c, --config <path> Wrangler config path
31
37
  -p, --profiles <path> Profiles directory
32
- --json JSON output for list/status
38
+ --json JSON output for all commands
39
+ --plain Plain output for list (one name per line)
33
40
  -f, --force Overwrite existing profile on save
34
41
  --backup Backup current config on use (default)
35
42
  --no-backup Disable backup on use
@@ -73,6 +80,8 @@ function parseArgs(argv) {
73
80
  opts.help = true;
74
81
  } else if (arg === "--json") {
75
82
  opts.json = true;
83
+ } else if (arg === "--plain") {
84
+ opts.plain = true;
76
85
  } else if (arg === "--force" || arg === "-f") {
77
86
  opts.force = true;
78
87
  } else if (arg === "--backup") {
@@ -287,7 +296,9 @@ function removeProfile(name, profilesDir) {
287
296
  }
288
297
 
289
298
  function main() {
290
- const { opts, rest } = parseArgs(process.argv.slice(2));
299
+ const argv = process.argv.slice(2);
300
+ outputJson = argv.includes("--json");
301
+ const { opts, rest } = parseArgs(argv);
291
302
  if (opts.help) printHelp(0);
292
303
 
293
304
  const command = rest[0];
@@ -300,6 +311,8 @@ function main() {
300
311
  const profiles = listProfiles(profilesDir);
301
312
  if (opts.json) {
302
313
  console.log(JSON.stringify(profiles, null, 2));
314
+ } else if (opts.plain) {
315
+ if (profiles.length) console.log(profiles.join("\n"));
303
316
  } else if (profiles.length === 0) {
304
317
  console.log("No profiles found.");
305
318
  } else {
@@ -337,8 +350,26 @@ function main() {
337
350
  const name = rest[1];
338
351
  if (!name) die("Missing profile name for save");
339
352
  ensureDir(profilesDir);
353
+ const profileDir = path.join(profilesDir, name);
354
+ const existed = fs.existsSync(profileDir);
340
355
  saveProfile(name, configPath, profilesDir, opts.force);
341
- console.log(`Saved profile '${name}' from ${configPath}`);
356
+ if (opts.json) {
357
+ console.log(
358
+ JSON.stringify(
359
+ {
360
+ command: "save",
361
+ name,
362
+ configPath,
363
+ profilesDir,
364
+ overwritten: existed,
365
+ },
366
+ null,
367
+ 2
368
+ )
369
+ );
370
+ } else {
371
+ console.log(`Saved profile '${name}' from ${configPath}`);
372
+ }
342
373
  return;
343
374
  }
344
375
 
@@ -354,7 +385,23 @@ function main() {
354
385
  const existed = fs.existsSync(profileDir);
355
386
  saveProfile(name, configPath, profilesDir, true);
356
387
  const note = existed ? " (overwritten)" : "";
357
- console.log(`Logged in and saved profile '${name}' from ${configPath}${note}`);
388
+ if (opts.json) {
389
+ console.log(
390
+ JSON.stringify(
391
+ {
392
+ command: "login",
393
+ name,
394
+ configPath,
395
+ profilesDir,
396
+ overwritten: existed,
397
+ },
398
+ null,
399
+ 2
400
+ )
401
+ );
402
+ } else {
403
+ console.log(`Logged in and saved profile '${name}' from ${configPath}${note}`);
404
+ }
358
405
  return;
359
406
  }
360
407
 
@@ -364,7 +411,23 @@ function main() {
364
411
  ensureDir(profilesDir);
365
412
  const backupName = useProfile(name, configPath, profilesDir, opts.backup);
366
413
  const backupNote = backupName ? ` (backup: ${backupName})` : "";
367
- console.log(`Switched to profile '${name}'${backupNote}`);
414
+ if (opts.json) {
415
+ console.log(
416
+ JSON.stringify(
417
+ {
418
+ command: "use",
419
+ name,
420
+ configPath,
421
+ profilesDir,
422
+ backupName,
423
+ },
424
+ null,
425
+ 2
426
+ )
427
+ );
428
+ } else {
429
+ console.log(`Switched to profile '${name}'${backupNote}`);
430
+ }
368
431
  return;
369
432
  }
370
433
 
@@ -372,7 +435,21 @@ function main() {
372
435
  const name = rest[1];
373
436
  if (!name) die("Missing profile name for remove");
374
437
  removeProfile(name, profilesDir);
375
- console.log(`Removed profile '${name}'`);
438
+ if (opts.json) {
439
+ console.log(
440
+ JSON.stringify(
441
+ {
442
+ command: "remove",
443
+ name,
444
+ profilesDir,
445
+ },
446
+ null,
447
+ 2
448
+ )
449
+ );
450
+ } else {
451
+ console.log(`Removed profile '${name}'`);
452
+ }
376
453
  return;
377
454
  }
378
455
 
@@ -0,0 +1,36 @@
1
+ #compdef wrangler-accounts
2
+
3
+ _wrangler_accounts() {
4
+ local -a commands
5
+ commands=(
6
+ 'list:List profiles'
7
+ 'status:Show status'
8
+ 'login:Login and save profile'
9
+ 'save:Save current profile'
10
+ 'use:Switch to profile'
11
+ 'remove:Remove profile'
12
+ )
13
+
14
+ local state
15
+ _arguments -C \
16
+ '1:command:->command' \
17
+ '*::arg:->args'
18
+
19
+ case $state in
20
+ command)
21
+ _describe 'command' commands
22
+ return
23
+ ;;
24
+ args)
25
+ case $words[1] in
26
+ save|use|remove|login)
27
+ local profiles
28
+ profiles=(${(f)"$(wrangler-accounts list --plain 2>/dev/null | grep -v '^__backup-')"})
29
+ _describe 'profiles' profiles
30
+ ;;
31
+ esac
32
+ ;;
33
+ esac
34
+ }
35
+
36
+ _wrangler_accounts "$@"
package/package.json CHANGED
@@ -1,18 +1,23 @@
1
1
  {
2
2
  "name": "@leeguoo/wrangler-accounts",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Local CLI to manage multiple Cloudflare Wrangler login profiles.",
5
5
  "license": "MIT",
6
6
  "bin": {
7
7
  "wrangler-accounts": "bin/wrangler-accounts.js"
8
8
  },
9
9
  "files": [
10
- "bin"
10
+ "bin",
11
+ "completions"
11
12
  ],
12
13
  "keywords": [
13
14
  "cloudflare",
14
15
  "wrangler",
16
+ "cloudflare-workers",
17
+ "workers",
15
18
  "accounts",
19
+ "multi-account",
20
+ "account-switcher",
16
21
  "cli"
17
22
  ],
18
23
  "repository": {