Skip to content

Commit adbda8e

Browse files
committed
fix me version --no-server flag colliding with global --server
The --no-server boolean and the global --server <url> flag share the same opts key under commander, so optsWithGlobals() was returning true (the --no-server default) instead of a URL string. That fed into normalizeOrigin and crashed with 'url2.replace is not a function'. - Rename --no-server to --local to avoid the collision. - Guard with typeof === 'string' before passing to resolveServer. - Add a TypeError at the top of normalizeOrigin so a similar mishap surfaces a clear error instead of a cryptic one.
1 parent 3e5dd27 commit adbda8e

3 files changed

Lines changed: 21 additions & 8 deletions

File tree

docs/cli/me-version.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Show CLI and server versions and check compatibility.
55
## Usage
66

77
```
8-
me version [--no-server]
8+
me version [--local]
99
```
1010

1111
## Description
@@ -30,7 +30,7 @@ instead of obscure errors mid-login.
3030

3131
| Option | Description |
3232
|--------|-------------|
33-
| `--no-server` | Skip the server probe; print only the local CLI version. |
33+
| `--local` | Skip the server probe; print only the local CLI version. |
3434

3535
## Global Options
3636

@@ -57,7 +57,7 @@ me version --server https://api.memory.build
5757
Local-only output (e.g. on an air-gapped machine):
5858

5959
```
60-
me version --no-server
60+
me version --local
6161
```
6262

6363
JSON output for scripts and CI:

packages/cli/commands/version.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ export function createVersionCommand(): Command {
2121
return new Command("version")
2222
.description("show CLI and server versions and check compatibility")
2323
.option(
24-
"--no-server",
25-
"skip the server check; print only the local CLI version",
24+
"--local",
25+
"skip the server probe; print only the local CLI version",
2626
)
27-
.action(async (opts: { server: boolean }, cmd) => {
27+
.action(async (opts: { local?: boolean }, cmd) => {
2828
const globalOpts = cmd.optsWithGlobals();
2929
const fmt = getOutputFormat(globalOpts);
3030

@@ -39,15 +39,20 @@ export function createVersionCommand(): Command {
3939
bundledMinClientVersion: MIN_CLIENT_VERSION,
4040
};
4141

42-
if (!opts.server) {
42+
if (opts.local) {
4343
await output({ ...local, server: null }, fmt, () => {
4444
console.log(` Client version: ${local.clientVersion}`);
4545
console.log(` Min server: ${local.minServerVersion}`);
4646
});
4747
return;
4848
}
4949

50-
const server = resolveServer(globalOpts.server);
50+
// The global option is `--server <url>` and may also leak through as
51+
// `globalOpts.server` for parent flags. Only pass it through to
52+
// resolveServer when it is actually a string.
53+
const serverFlag =
54+
typeof globalOpts.server === "string" ? globalOpts.server : undefined;
55+
const server = resolveServer(serverFlag);
5156

5257
try {
5358
const probe = await checkServerVersion({

packages/cli/credentials.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ function getCredentialsPath(): string {
9393
* Strips trailing slashes and default ports.
9494
*/
9595
export function normalizeOrigin(url: string): string {
96+
// Defense in depth: this function gets called with values that flow in
97+
// from CLI flags, env vars, and YAML files. Throwing a clear error beats
98+
// a cryptic "url2.replace is not a function" downstream.
99+
if (typeof url !== "string") {
100+
throw new TypeError(
101+
`Expected server URL to be a string, got ${typeof url}`,
102+
);
103+
}
96104
try {
97105
const parsed = new URL(url);
98106
// Remove default ports

0 commit comments

Comments
 (0)