diff --git a/src/commands/auth.ts b/src/commands/auth.ts index c2aa7420..92596ad9 100644 --- a/src/commands/auth.ts +++ b/src/commands/auth.ts @@ -8,8 +8,7 @@ import {DEV} from '../env'; import {loginEmulatorOnly} from '../services/auth/login.emulator.services'; import {login as loginServices} from '../services/auth/login.services'; import {reuseController} from '../services/controllers.services'; -import {isHeadless} from '../utils/process.utils'; -import {confirmAndExit} from '../utils/prompt.utils'; +import {confirmAndExitUnlessHeadlessAndDev} from '../utils/prompt.utils'; export const logout = async () => { await clearCliConfig(); @@ -63,11 +62,6 @@ const emulatorLogin = async () => { return; } - if (isHeadless()) { - await loginEmulatorOnly(); - return; - } - const token = await getToken(); if (isNullish(token)) { @@ -78,7 +72,7 @@ const emulatorLogin = async () => { const identity = Ed25519KeyIdentity.fromParsedJson(token); console.log(`🔐 Your terminal already has access: ${green(identity.getPrincipal().toText())}\n`); - await confirmAndExit( + await confirmAndExitUnlessHeadlessAndDev( 'Would you like to overwrite the saved development authentication on this device' ); diff --git a/src/services/modules/snapshot/_snapshot.loader.services.ts b/src/services/modules/snapshot/_snapshot.loader.services.ts index f9900118..687b6c1f 100644 --- a/src/services/modules/snapshot/_snapshot.loader.services.ts +++ b/src/services/modules/snapshot/_snapshot.loader.services.ts @@ -7,7 +7,7 @@ import ora from 'ora'; import {listCanisterSnapshots} from '../../../api/ic.api'; import type {AssetKey} from '../../../types/asset-key'; import {displaySegment} from '../../../utils/display.utils'; -import {confirmAndExit} from '../../../utils/prompt.utils'; +import {confirmAndExitUnlessHeadlessAndDev} from '../../../utils/prompt.utils'; const loadSnapshot = async ({ canisterId @@ -54,7 +54,7 @@ export const loadSnapshotAndAssertOverwrite = async ({ const existingSnapshotId = await loadSnapshot({canisterId}); if (nonNullish(existingSnapshotId)) { - await confirmAndExit( + await confirmAndExitUnlessHeadlessAndDev( `A snapshot for your ${displaySegment(segment)} already exists with ID 0x${encodeSnapshotId(existingSnapshotId)}. Do you want to overwrite it?` ); } diff --git a/src/services/modules/snapshot/snapshot.services.ts b/src/services/modules/snapshot/snapshot.services.ts index d4979295..71871083 100644 --- a/src/services/modules/snapshot/snapshot.services.ts +++ b/src/services/modules/snapshot/snapshot.services.ts @@ -12,7 +12,7 @@ import { import type {AssetKey} from '../../../types/asset-key'; import {displaySegment} from '../../../utils/display.utils'; import {assertNonNullishFolderExists} from '../../../utils/fs.utils'; -import {confirmAndExit} from '../../../utils/prompt.utils'; +import {confirmAndExitUnlessHeadlessAndDev} from '../../../utils/prompt.utils'; import {assertMatchingJunoPackage} from './_snapshot.assert.services'; import { loadSnapshotAndAssertExist, @@ -56,7 +56,7 @@ export const restoreSnapshot = async ({ const {snapshotId: existingSnapshotId} = result; - await confirmAndExit( + await confirmAndExitUnlessHeadlessAndDev( `Restoring the snapshot 0x${encodeSnapshotId(existingSnapshotId)} will permanently overwrite the current state of your ${displaySegment(segment)}. Are you sure you want to proceed?` ); @@ -84,7 +84,7 @@ export const deleteSnapshot = async ({ const {snapshotId: existingSnapshotId} = result; - await confirmAndExit( + await confirmAndExitUnlessHeadlessAndDev( `Are you sure you want to delete the snapshot 0x${encodeSnapshotId(existingSnapshotId)} of your ${displaySegment(segment)}?` ); diff --git a/src/utils/prompt.utils.ts b/src/utils/prompt.utils.ts index eac51991..d3649d6b 100644 --- a/src/utils/prompt.utils.ts +++ b/src/utils/prompt.utils.ts @@ -1,4 +1,6 @@ import prompts from 'prompts'; +import {DEV} from '../env'; +import {isHeadless} from './process.utils'; export const NEW_CMD_LINE = '\n '; @@ -46,3 +48,11 @@ export const confirmAndExit = async (message: string) => { process.exit(1); } }; + +export const confirmAndExitUnlessHeadlessAndDev = async (message: string) => { + if (isHeadless() && DEV) { + return; + } + + await confirmAndExit(message); +};