Skip to content

Commit 4725173

Browse files
fix: [PR-1797] suppress migration banner after sf migrate completes (#269)
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent a0ff01a commit 4725173

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/helpers/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface Config {
1111
webapp_url: string;
1212
auth_token?: string;
1313
account_id?: string;
14+
migrated_to_rust_cli?: boolean;
1415
}
1516

1617
const ProductionConfigDefaults = {

src/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ async function main() {
4242
process.env.SF_CLI_DISABLE_AUTO_UPGRADE = "1";
4343
}
4444

45+
// Load config early so the migration banner can honor the persisted
46+
// `migrated_to_rust_cli` flag written by a successful `sf migrate`.
47+
const config = await loadConfig();
48+
4549
if (!process.argv.includes("--json")) {
4650
const [shownUpgradeBanner] = await Promise.all([
4751
checkVersion(),
@@ -51,14 +55,16 @@ async function main() {
5155
// them toward the new Rust CLI instead of showing nothing. We avoid
5256
// double-stacking with the upgrade banner since users on outdated builds
5357
// need to upgrade before migrating, and skip the banner for the
54-
// `upgrade` / `migrate` commands themselves (where it'd just be noise)
55-
// and for users who've opted out via SF_CLI_DISABLE_MIGRATE_BANNER.
58+
// `upgrade` / `migrate` commands themselves (where it'd just be noise),
59+
// for users who've opted out via SF_CLI_DISABLE_MIGRATE_BANNER, and for
60+
// users who've already migrated (the flag is set by `sf migrate`).
5661
const subcommand = process.argv[2];
5762
if (
5863
!shownUpgradeBanner &&
5964
subcommand !== "migrate" &&
6065
subcommand !== "upgrade" &&
61-
!process.env.SF_CLI_DISABLE_MIGRATE_BANNER
66+
!process.env.SF_CLI_DISABLE_MIGRATE_BANNER &&
67+
!config.migrated_to_rust_cli
6268
) {
6369
showMigrateBanner();
6470
}
@@ -73,7 +79,6 @@ async function main() {
7379
// surfaces (e.g. `--enable-infiniband` on `sf nodes create`) resolve
7480
// correctly on the very first CLI invocation after login, rather than only
7581
// appearing after the cache has been seeded by a previous run.
76-
const config = await loadConfig();
7782
let exchangeAccountId = config.account_id;
7883
if (!exchangeAccountId) {
7984
const client = await apiClient(config.auth_token);

src/lib/migrate.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Command } from "@commander-js/extra-typings";
55
import boxen from "boxen";
66
import chalk from "chalk";
77
import ora from "ora";
8+
import { loadConfig, saveConfig } from "../helpers/config.ts";
89

910
const NEW_CLI_INSTALL_URL = "https://cli.sfcompute.com";
1011
const MIGRATION_GUIDE_URL = "https://sfcompute.com/migrate";
@@ -99,6 +100,15 @@ export function registerMigrate(program: Command) {
99100
}
100101
}
101102

103+
// Persist a flag so future `sf-old` invocations don't nag the user with
104+
// the migration banner.
105+
try {
106+
const config = await loadConfig();
107+
await saveConfig({ ...config, migrated_to_rust_cli: true });
108+
} catch {
109+
// Best-effort: a failure here just means the banner keeps showing.
110+
}
111+
102112
console.log(
103113
boxen(
104114
chalk.cyan(

0 commit comments

Comments
 (0)