Skip to content

Commit 6124cf0

Browse files
authored
fix(cli): direct users to geonic cli update and suppress redundant notice (#124)
* fix(cli): direct users to `geonic cli update` and suppress redundant notice - アップデート通知ボックスの案内を `npm i -g @geolonia/geonicdb-cli` から `geonic cli update` に変更し、CLI 内蔵の更新コマンドへ誘導 - `geonic cli update` 実行後にプロセス末尾で同じ通知が再表示されてしまう 問題を修正 — 成功時に通知出力を抑制 * docs(changelog): add PR reference for #124
1 parent 5bcdbd3 commit 6124cf0

5 files changed

Lines changed: 27 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
## [Unreleased]
99

1010
### 2026-05-13
11+
- **Fix**: アップデート通知のメッセージを `npm i -g @geolonia/geonicdb-cli` から `geonic cli update` に変更 — CLI 内蔵のアップデートコマンドを案内するように (#124)
12+
- **Fix**: `geonic cli update` 実行後に同セッション末尾でアップデート通知が再表示される問題を修正 — `update` コマンド成功時に通知出力を抑制 (#124)
1113
- **Feat**: `profile create``--tenant <tenant>` オプションを追加 — プロファイル作成時にテナント ID/名を初期値として束縛できるように。`--url` (グローバルフラグ) と組み合わせて、同じアカウントの別テナントごとに独立したプロファイルを一度に生成可能 (例: `geonic profile create miya --tenant miya` / `geonic profile create geolonia --tenant geolonia`) (#123)
1214
- **Breaking**: `auth login` の複数テナント所属時の挙動を変更 — 対話プロンプトによるテナント選択を廃止し、`--tenant-id` または `-s/--service` の明示指定を必須化。未指定で複数所属を検出した場合は利用可能テナント一覧を表示してエラー終了する。プロファイル設定で `service`/`tenantId` を保持していれば自動解決される (#123)
1315
- **Refactor**: `src/prompt.ts` から `promptTenantSelection` / `TenantChoice` を削除。`src/commands/auth.ts``types.ts``TenantInfo` を参照するように統一 (#123)

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands/cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createRequire } from "node:module";
33
import type { Command, Option } from "commander";
44
import { printInfo, printSuccess } from "../output.js";
55
import { withErrorHandler, resolveOptions } from "../helpers.js";
6+
import { suppressUpdateNotification } from "../update-notifier.js";
67
import { addExamples } from "./help.js";
78

89
function findOption(
@@ -297,6 +298,7 @@ export function registerCliCommand(program: Command): void {
297298
}
298299
printInfo("Updating @geolonia/geonicdb-cli...");
299300
execSync(updateCommand, { stdio: "inherit" });
301+
suppressUpdateNotification();
300302
printSuccess("Update complete.");
301303
}),
302304
);

src/update-notifier.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function getCurrentVersion(): string {
9696

9797
export function formatUpdateBox(current: string, latest: string): string {
9898
const message = `Update available: ${current}${latest}`;
99-
const install = `Run ${chalk.cyan(`npm i -g ${PACKAGE_NAME}`)} to update`;
99+
const install = `Run ${chalk.cyan(`geonic cli update`)} to update`;
100100
const lines = [message, install];
101101
const maxLen = Math.max(
102102
...lines.map((l) => stripAnsi(l).length),
@@ -162,7 +162,14 @@ export async function startUpdateCheck(): Promise<UpdateCheckResult | null> {
162162
return null;
163163
}
164164

165+
let notificationSuppressed = false;
166+
167+
export function suppressUpdateNotification(): void {
168+
notificationSuppressed = true;
169+
}
170+
165171
export function printUpdateNotification(result: UpdateCheckResult | null): void {
172+
if (notificationSuppressed) return;
166173
if (!result) return;
167174
const box = formatUpdateBox(result.currentVersion, result.latestVersion);
168175
process.stderr.write("\n" + box + "\n");

tests/update-notifier.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ describe("formatUpdateBox", () => {
125125
expect(box).toContain("0.1.0");
126126
expect(box).toContain("1.0.0");
127127
expect(box).toContain("Update available");
128-
expect(box).toContain("npm i -g @geolonia/geonicdb-cli");
128+
expect(box).toContain("geonic cli update");
129129
expect(box).toContain("╭");
130130
expect(box).toContain("╰");
131131
});
@@ -419,9 +419,13 @@ describe("startUpdateCheck", () => {
419419

420420
describe("printUpdateNotification", () => {
421421
let printUpdateNotification: typeof import("../src/update-notifier.js").printUpdateNotification;
422+
let suppressUpdateNotification: typeof import("../src/update-notifier.js").suppressUpdateNotification;
422423

423424
beforeEach(async () => {
424-
({ printUpdateNotification } = await import("../src/update-notifier.js"));
425+
vi.resetModules();
426+
({ printUpdateNotification, suppressUpdateNotification } = await import(
427+
"../src/update-notifier.js"
428+
));
425429
});
426430

427431
it("writes box to stderr when result is provided", () => {
@@ -455,6 +459,13 @@ describe("printUpdateNotification", () => {
455459
printUpdateNotification(null);
456460
expect(writeSpy).not.toHaveBeenCalled();
457461
});
462+
463+
it("does nothing when suppressed", () => {
464+
const writeSpy = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
465+
suppressUpdateNotification();
466+
printUpdateNotification({ currentVersion: "0.1.0", latestVersion: "1.0.0" });
467+
expect(writeSpy).not.toHaveBeenCalled();
468+
});
458469
});
459470

460471
describe("CI environment variables", () => {

0 commit comments

Comments
 (0)