postman-cli-completion 1.71.0 → 1.74.0

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
@@ -119,6 +119,74 @@ After installing for your shell, open a fresh terminal and check each:
119
119
  | `postman flows <TAB>` | `list`, `trigger`, `deploy`, `run`, `update`, `list-runs`, `get-run` |
120
120
  | `postman --<TAB>` | `--silent`, `--color`, `--version`, `--help` |
121
121
 
122
+ ## Check your Postman CLI version
123
+
124
+ The completions are generated for a specific Postman CLI version, so a CLI that has
125
+ drifted from that version may complete commands it does not have (or miss ones it does).
126
+ `doctor` reports both kinds of drift:
127
+
128
+ ```sh
129
+ postman-completion doctor
130
+ ```
131
+
132
+ It performs two independent checks:
133
+
134
+ 1. **Installed CLI vs. the latest published `postman-cli`** — if yours is older, it warns
135
+ and tells you how to upgrade.
136
+ 2. **Installed CLI vs. the version these completions were generated for** — if they differ,
137
+ it warns and tells you how to update the completions.
138
+
139
+ ```console
140
+ $ postman-completion doctor
141
+ Your Postman CLI is outdated: installed 1.60.0, latest 1.73.0.
142
+ Upgrade with: npm install -g postman-cli@latest
143
+ These completions were generated for Postman CLI 1.73.0, but 1.60.0 is installed.
144
+ Completions may offer commands your CLI does not have.
145
+ Update them with: npm install -g postman-cli-completion@latest
146
+ ```
147
+
148
+ Check 1 queries the npm registry. To skip it — offline, or in a hook where you do not want
149
+ a network call — use `--offline`, which still runs check 2:
150
+
151
+ ```sh
152
+ postman-completion doctor --offline
153
+ ```
154
+
155
+ `doctor` exits **1** when you should act (outdated CLI, or completions that no longer match
156
+ it) and **0** when everything is current, so it works as a shell-startup or CI check. A
157
+ missing Postman CLI is reported as a notice and exits 0. A failed registry lookup never
158
+ fails the command — it degrades to the offline check and explains itself on stderr.
159
+
160
+ ### Automatic notice on install
161
+
162
+ You do not have to remember to run `doctor`. Installing or updating this package prints a
163
+ notice if your Postman CLI does not match the version the completions were built for:
164
+
165
+ ```console
166
+ $ npm install -g postman-cli-completion
167
+
168
+ postman-cli-completion:
169
+ These completions were generated for Postman CLI 1.73.0, but 1.60.0 is installed.
170
+ Completions may offer commands your CLI does not have.
171
+ Update them with: npm install -g postman-cli-completion@latest
172
+
173
+ Silence this check with POSTMAN_COMPLETION_NO_VERSION_CHECK=1
174
+ ```
175
+
176
+ This check is deliberately conservative:
177
+
178
+ - **Never fails the install** — it exits 0 on every path, including unexpected errors.
179
+ - **Never touches the network** — the comparison is local, so installs stay fast and
180
+ offline-safe. The "is my CLI older than the latest release?" question needs the
181
+ registry, so it belongs to `doctor`.
182
+ - **Silent unless it matters** — nothing is printed when the versions match, when the
183
+ Postman CLI is not installed, in CI, for non-global installs, or when stderr is not a
184
+ terminal. Set `POSTMAN_COMPLETION_NO_VERSION_CHECK=1` to disable it entirely.
185
+
186
+ Because it runs at install time, it catches drift when you install or update this package.
187
+ If you upgrade the Postman CLI itself some time later, run `postman-completion doctor` to
188
+ check on demand.
189
+
122
190
  ## Versioning
123
191
 
124
192
  The completion scripts are auto-generated from a single source of truth (`spec/commands.json`) and tracked against the upstream Postman CLI by two GitHub Actions workflows:
@@ -130,16 +198,12 @@ So this repo follows the latest published Postman CLI version automatically —
130
198
 
131
199
  Suspicious catchup diffs (≥30 % flag drop, a known fixed command missing, semver regression) are blocked by `scripts/validate-diff.mjs` and stay open for human review instead of auto-merging.
132
200
 
133
- To check the version the committed spec was generated against:
134
-
135
- ```sh
136
- node -p "require('./spec/commands.json').postmanCliVersion"
137
- ```
138
-
139
- And your installed Postman CLI:
201
+ To compare the version the completions were built for against your installed CLI, use
202
+ [`postman-completion doctor`](#check-your-postman-cli-version). The underlying values are:
140
203
 
141
204
  ```sh
142
- postman --version
205
+ node -p "require('./spec/commands.json').postmanCliVersion" # what the completions target
206
+ postman --version # what you have installed
143
207
  ```
144
208
 
145
209
  ## License
@@ -2,6 +2,7 @@
2
2
  import { readFileSync } from "node:fs";
3
3
  import { dirname, resolve } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
+ import { checkVersions } from "../lib/version-check.mjs";
5
6
 
6
7
  // bin/ lives one level under the package root. Resolve completion files relative
7
8
  // to this module (NOT process.cwd(), which is the user's shell directory).
@@ -13,6 +14,9 @@ const FILES = {
13
14
  fish: resolve(PKG_ROOT, "completions/fish/postman.fish"),
14
15
  };
15
16
 
17
+ const SPEC_PATH = resolve(PKG_ROOT, "spec/commands.json");
18
+ const PKG_JSON_PATH = resolve(PKG_ROOT, "package.json");
19
+
16
20
  const USAGE = `postman-completion — shell completions for the Postman CLI
17
21
 
18
22
  Note: this installs the command "postman-completion"; it does NOT shadow the
@@ -22,6 +26,8 @@ Usage:
22
26
  postman-completion <zsh|bash|fish> Print the completion script to stdout
23
27
  postman-completion path <zsh|bash|fish> Print the packaged file's absolute path
24
28
  postman-completion path <shell> --dir Print the file's directory (for zsh fpath)
29
+ postman-completion doctor Check your Postman CLI version for updates
30
+ postman-completion doctor --offline Same, without querying the npm registry
25
31
  postman-completion --help Show this help
26
32
 
27
33
  Wire it into your shell:
@@ -59,7 +65,30 @@ function printPath(args) {
59
65
  process.stdout.write(`${dirOnly ? dirname(file) : file}\n`);
60
66
  }
61
67
 
62
- function main(argv) {
68
+ // Exit 0 when everything is current, 1 when the user should act (outdated CLI
69
+ // or completions that no longer match it), so `doctor` is usable in a script.
70
+ async function doctor(args) {
71
+ const offline = args.includes("--offline");
72
+ const report = await checkVersions({
73
+ specPath: SPEC_PATH,
74
+ packageJsonPath: PKG_JSON_PATH,
75
+ offline,
76
+ });
77
+
78
+ for (const line of report.lines) process.stdout.write(`${line}\n`);
79
+
80
+ // Surface *why* a comparison was skipped, but only when it hid information:
81
+ // an explicit --offline is the user's own choice and needs no explanation.
82
+ if (!offline && report.latestError) {
83
+ process.stderr.write(
84
+ `postman-completion: could not check npm for the latest version (${report.latestError})\n`,
85
+ );
86
+ }
87
+
88
+ process.exit(report.level === "warn" ? 1 : 0);
89
+ }
90
+
91
+ async function main(argv) {
63
92
  const [cmd, ...rest] = argv;
64
93
 
65
94
  if (!cmd || cmd === "--help" || cmd === "-h" || cmd === "help") {
@@ -72,6 +101,11 @@ function main(argv) {
72
101
  return;
73
102
  }
74
103
 
104
+ if (cmd === "doctor") {
105
+ await doctor(rest);
106
+ return;
107
+ }
108
+
75
109
  if (cmd in FILES) {
76
110
  emit(cmd);
77
111
  return;
@@ -80,4 +114,4 @@ function main(argv) {
80
114
  die(`unknown command: ${cmd}\n\n${USAGE}`);
81
115
  }
82
116
 
83
- main(process.argv.slice(2));
117
+ main(process.argv.slice(2)).catch((err) => die(err.message));