Skip to content

Commit 09f3b6a

Browse files
feat: snapshot and login emulator no confirm if headless and dev mode (#389)
1 parent e9b6f7c commit 09f3b6a

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

src/commands/auth.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import {DEV} from '../env';
88
import {loginEmulatorOnly} from '../services/auth/login.emulator.services';
99
import {login as loginServices} from '../services/auth/login.services';
1010
import {reuseController} from '../services/controllers.services';
11-
import {isHeadless} from '../utils/process.utils';
12-
import {confirmAndExit} from '../utils/prompt.utils';
11+
import {confirmAndExitUnlessHeadlessAndDev} from '../utils/prompt.utils';
1312

1413
export const logout = async () => {
1514
await clearCliConfig();
@@ -63,11 +62,6 @@ const emulatorLogin = async () => {
6362
return;
6463
}
6564

66-
if (isHeadless()) {
67-
await loginEmulatorOnly();
68-
return;
69-
}
70-
7165
const token = await getToken();
7266

7367
if (isNullish(token)) {
@@ -78,7 +72,7 @@ const emulatorLogin = async () => {
7872
const identity = Ed25519KeyIdentity.fromParsedJson(token);
7973
console.log(`🔐 Your terminal already has access: ${green(identity.getPrincipal().toText())}\n`);
8074

81-
await confirmAndExit(
75+
await confirmAndExitUnlessHeadlessAndDev(
8276
'Would you like to overwrite the saved development authentication on this device'
8377
);
8478

src/services/modules/snapshot/_snapshot.loader.services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ora from 'ora';
77
import {listCanisterSnapshots} from '../../../api/ic.api';
88
import type {AssetKey} from '../../../types/asset-key';
99
import {displaySegment} from '../../../utils/display.utils';
10-
import {confirmAndExit} from '../../../utils/prompt.utils';
10+
import {confirmAndExitUnlessHeadlessAndDev} from '../../../utils/prompt.utils';
1111

1212
const loadSnapshot = async ({
1313
canisterId
@@ -54,7 +54,7 @@ export const loadSnapshotAndAssertOverwrite = async ({
5454
const existingSnapshotId = await loadSnapshot({canisterId});
5555

5656
if (nonNullish(existingSnapshotId)) {
57-
await confirmAndExit(
57+
await confirmAndExitUnlessHeadlessAndDev(
5858
`A snapshot for your ${displaySegment(segment)} already exists with ID 0x${encodeSnapshotId(existingSnapshotId)}. Do you want to overwrite it?`
5959
);
6060
}

src/services/modules/snapshot/snapshot.services.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import type {AssetKey} from '../../../types/asset-key';
1313
import {displaySegment} from '../../../utils/display.utils';
1414
import {assertNonNullishFolderExists} from '../../../utils/fs.utils';
15-
import {confirmAndExit} from '../../../utils/prompt.utils';
15+
import {confirmAndExitUnlessHeadlessAndDev} from '../../../utils/prompt.utils';
1616
import {assertMatchingJunoPackage} from './_snapshot.assert.services';
1717
import {
1818
loadSnapshotAndAssertExist,
@@ -56,7 +56,7 @@ export const restoreSnapshot = async ({
5656

5757
const {snapshotId: existingSnapshotId} = result;
5858

59-
await confirmAndExit(
59+
await confirmAndExitUnlessHeadlessAndDev(
6060
`Restoring the snapshot 0x${encodeSnapshotId(existingSnapshotId)} will permanently overwrite the current state of your ${displaySegment(segment)}. Are you sure you want to proceed?`
6161
);
6262

@@ -84,7 +84,7 @@ export const deleteSnapshot = async ({
8484

8585
const {snapshotId: existingSnapshotId} = result;
8686

87-
await confirmAndExit(
87+
await confirmAndExitUnlessHeadlessAndDev(
8888
`Are you sure you want to delete the snapshot 0x${encodeSnapshotId(existingSnapshotId)} of your ${displaySegment(segment)}?`
8989
);
9090

src/utils/prompt.utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import prompts from 'prompts';
2+
import {DEV} from '../env';
3+
import {isHeadless} from './process.utils';
24

35
export const NEW_CMD_LINE = '\n ';
46

@@ -46,3 +48,11 @@ export const confirmAndExit = async (message: string) => {
4648
process.exit(1);
4749
}
4850
};
51+
52+
export const confirmAndExitUnlessHeadlessAndDev = async (message: string) => {
53+
if (isHeadless() && DEV) {
54+
return;
55+
}
56+
57+
await confirmAndExit(message);
58+
};

0 commit comments

Comments
 (0)