Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface Config {
webapp_url: string;
auth_token?: string;
account_id?: string;
migrated_to_rust_cli?: boolean;
}

const ProductionConfigDefaults = {
Expand Down
13 changes: 9 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ async function main() {
process.env.SF_CLI_DISABLE_AUTO_UPGRADE = "1";
}

// Load config early so the migration banner can honor the persisted
// `migrated_to_rust_cli` flag written by a successful `sf migrate`.
const config = await loadConfig();

if (!process.argv.includes("--json")) {
const [shownUpgradeBanner] = await Promise.all([
checkVersion(),
Expand All @@ -51,14 +55,16 @@ async function main() {
// them toward the new Rust CLI instead of showing nothing. We avoid
// double-stacking with the upgrade banner since users on outdated builds
// need to upgrade before migrating, and skip the banner for the
// `upgrade` / `migrate` commands themselves (where it'd just be noise)
// and for users who've opted out via SF_CLI_DISABLE_MIGRATE_BANNER.
// `upgrade` / `migrate` commands themselves (where it'd just be noise),
// for users who've opted out via SF_CLI_DISABLE_MIGRATE_BANNER, and for
// users who've already migrated (the flag is set by `sf migrate`).
const subcommand = process.argv[2];
if (
!shownUpgradeBanner &&
subcommand !== "migrate" &&
subcommand !== "upgrade" &&
!process.env.SF_CLI_DISABLE_MIGRATE_BANNER
!process.env.SF_CLI_DISABLE_MIGRATE_BANNER &&
!config.migrated_to_rust_cli
) {
showMigrateBanner();
}
Expand All @@ -73,7 +79,6 @@ async function main() {
// surfaces (e.g. `--enable-infiniband` on `sf nodes create`) resolve
// correctly on the very first CLI invocation after login, rather than only
// appearing after the cache has been seeded by a previous run.
const config = await loadConfig();
let exchangeAccountId = config.account_id;
if (!exchangeAccountId) {
const client = await apiClient(config.auth_token);
Expand Down
10 changes: 10 additions & 0 deletions src/lib/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Command } from "@commander-js/extra-typings";
import boxen from "boxen";
import chalk from "chalk";
import ora from "ora";
import { loadConfig, saveConfig } from "../helpers/config.ts";

const NEW_CLI_INSTALL_URL = "https://cli.sfcompute.com";
const MIGRATION_GUIDE_URL = "https://sfcompute.com/migrate";
Expand Down Expand Up @@ -99,6 +100,15 @@ export function registerMigrate(program: Command) {
}
}

// Persist a flag so future `sf-old` invocations don't nag the user with
// the migration banner.
try {
const config = await loadConfig();
await saveConfig({ ...config, migrated_to_rust_cli: true });
} catch {
// Best-effort: a failure here just means the banner keeps showing.
}

console.log(
boxen(
chalk.cyan(
Expand Down
Loading