Skip to content

Commit 84b6690

Browse files
committed
batch2
1 parent 98460bb commit 84b6690

12 files changed

Lines changed: 357 additions & 19 deletions

File tree

src/commands/actors/rm.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ApifyApiError } from 'apify-client';
22

33
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
44
import { Args } from '../../lib/command-framework/args.js';
5+
import { YesFlag } from '../../lib/command-framework/flags.js';
56
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
67
import { error, info, success } from '../../lib/outputs.js';
78
import { getLoggedClientOrThrow } from '../../lib/utils.js';
@@ -18,8 +19,13 @@ export class ActorsRmCommand extends ApifyCommand<typeof ActorsRmCommand> {
1819
}),
1920
};
2021

22+
static override flags = {
23+
...YesFlag,
24+
};
25+
2126
async run() {
2227
const { actorId } = this.args;
28+
const { yes } = this.flags;
2329

2430
const apifyClient = await getLoggedClientOrThrow();
2531

@@ -32,6 +38,7 @@ export class ActorsRmCommand extends ApifyCommand<typeof ActorsRmCommand> {
3238

3339
const confirmedDelete = await useYesNoConfirm({
3440
message: `Are you sure you want to delete this Actor?`,
41+
providedConfirmFromStdin: yes || undefined,
3542
});
3643

3744
if (!confirmedDelete) {

src/commands/builds/remove-tag.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ActorTaggedBuild, ApifyApiError } from 'apify-client';
22
import chalk from 'chalk';
33

44
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
5-
import { Flags } from '../../lib/command-framework/flags.js';
5+
import { Flags, YesFlag } from '../../lib/command-framework/flags.js';
66
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
77
import { error, info, success } from '../../lib/outputs.js';
88
import { getLoggedClientOrThrow } from '../../lib/utils.js';
@@ -23,11 +23,7 @@ export class BuildsRemoveTagCommand extends ApifyCommand<typeof BuildsRemoveTagC
2323
description: 'The tag to remove from the build.',
2424
required: true,
2525
}),
26-
yes: Flags.boolean({
27-
char: 'y',
28-
description: 'Automatic yes to prompts; assume "yes" as answer to all prompts.',
29-
default: false,
30-
}),
26+
...YesFlag,
3127
};
3228

3329
async run() {

src/commands/builds/rm.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ActorTaggedBuild, ApifyApiError } from 'apify-client';
22

33
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
44
import { Args } from '../../lib/command-framework/args.js';
5+
import { YesFlag } from '../../lib/command-framework/flags.js';
56
import { useInputConfirmation } from '../../lib/hooks/user-confirmations/useInputConfirmation.js';
67
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
78
import { error, info, success } from '../../lib/outputs.js';
@@ -19,8 +20,13 @@ export class BuildsRmCommand extends ApifyCommand<typeof BuildsRmCommand> {
1920
}),
2021
};
2122

23+
static override flags = {
24+
...YesFlag,
25+
};
26+
2227
async run() {
2328
const { buildId } = this.args;
29+
const { yes } = this.flags;
2430

2531
const apifyClient = await getLoggedClientOrThrow();
2632

@@ -46,11 +52,21 @@ export class BuildsRmCommand extends ApifyCommand<typeof BuildsRmCommand> {
4652
}
4753

4854
// If the build is tagged, console asks you to confirm by typing in the tag. Otherwise, it asks you to confirm with a yes/no question.
49-
const confirmed = await (confirmationPrompt ? useInputConfirmation : useYesNoConfirm)({
50-
message: `Are you sure you want to delete this Actor Build?${confirmationPrompt ? ` If so, please type in "${confirmationPrompt}":` : ''}`,
51-
expectedValue: confirmationPrompt ?? '',
52-
failureMessage: 'Your provided value does not match the build tag.',
53-
});
55+
let confirmed: string | boolean;
56+
57+
if (confirmationPrompt) {
58+
confirmed = await useInputConfirmation({
59+
message: `Are you sure you want to delete this Actor Build? If so, please type in "${confirmationPrompt}":`,
60+
expectedValue: confirmationPrompt,
61+
failureMessage: 'Your provided value does not match the build tag.',
62+
providedConfirmFromStdin: yes ? confirmationPrompt : undefined,
63+
});
64+
} else {
65+
confirmed = await useYesNoConfirm({
66+
message: `Are you sure you want to delete this Actor Build?`,
67+
providedConfirmFromStdin: yes || undefined,
68+
});
69+
}
5470

5571
if (!confirmed) {
5672
info({

src/commands/datasets/rm.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import chalk from 'chalk';
33

44
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
55
import { Args } from '../../lib/command-framework/args.js';
6+
import { YesFlag } from '../../lib/command-framework/flags.js';
67
import { tryToGetDataset } from '../../lib/commands/storages.js';
78
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
89
import { error, info, success } from '../../lib/outputs.js';
@@ -20,8 +21,13 @@ export class DatasetsRmCommand extends ApifyCommand<typeof DatasetsRmCommand> {
2021
}),
2122
};
2223

24+
static override flags = {
25+
...YesFlag,
26+
};
27+
2328
async run() {
2429
const { datasetNameOrId } = this.args;
30+
const { yes } = this.flags;
2531

2632
const client = await getLoggedClientOrThrow();
2733

@@ -37,6 +43,7 @@ export class DatasetsRmCommand extends ApifyCommand<typeof DatasetsRmCommand> {
3743

3844
const confirmed = await useYesNoConfirm({
3945
message: `Are you sure you want to delete this Dataset?`,
46+
providedConfirmFromStdin: yes || undefined,
4047
});
4148

4249
if (!confirmed) {

src/commands/init.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import process from 'node:process';
33

44
import { ApifyCommand } from '../lib/command-framework/apify-command.js';
55
import { Args } from '../lib/command-framework/args.js';
6-
import { Flags } from '../lib/command-framework/flags.js';
6+
import { Flags, YesFlag } from '../lib/command-framework/flags.js';
77
import { CommandExitCodes, DEFAULT_LOCAL_STORAGE_DIR, EMPTY_LOCAL_CONFIG, LOCAL_CONFIG_PATH } from '../lib/consts.js';
88
import { useActorConfig } from '../lib/hooks/useActorConfig.js';
99
import { ProjectLanguage, useCwdProject } from '../lib/hooks/useCwdProject.js';
@@ -31,12 +31,7 @@ export class InitCommand extends ApifyCommand<typeof InitCommand> {
3131
};
3232

3333
static override flags = {
34-
yes: Flags.boolean({
35-
char: 'y',
36-
description:
37-
'Automatic yes to prompts; assume "yes" as answer to all prompts. Note that in some cases, the command may still ask for confirmation.',
38-
required: false,
39-
}),
34+
...YesFlag,
4035
dockerfile: Flags.string({
4136
description: 'Path to a Dockerfile to use for the Actor (e.g., "./Dockerfile" or "./docker/Dockerfile").',
4237
required: false,

src/commands/key-value-stores/delete-value.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import chalk from 'chalk';
33

44
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
55
import { Args } from '../../lib/command-framework/args.js';
6+
import { YesFlag } from '../../lib/command-framework/flags.js';
67
import { tryToGetKeyValueStore } from '../../lib/commands/storages.js';
78
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
89
import { error, info } from '../../lib/outputs.js';
@@ -24,8 +25,13 @@ export class KeyValueStoresDeleteValueCommand extends ApifyCommand<typeof KeyVal
2425
}),
2526
};
2627

28+
static override flags = {
29+
...YesFlag,
30+
};
31+
2732
async run() {
2833
const { storeId, itemKey } = this.args;
34+
const { yes } = this.flags;
2935

3036
const apifyClient = await getLoggedClientOrThrow();
3137
const maybeStore = await tryToGetKeyValueStore(apifyClient, storeId);
@@ -51,6 +57,7 @@ export class KeyValueStoresDeleteValueCommand extends ApifyCommand<typeof KeyVal
5157

5258
const confirm = await useYesNoConfirm({
5359
message: `Are you sure you want to delete this record?`,
60+
providedConfirmFromStdin: yes || undefined,
5461
});
5562

5663
if (!confirm) {

src/commands/key-value-stores/rm.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import chalk from 'chalk';
33

44
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
55
import { Args } from '../../lib/command-framework/args.js';
6+
import { YesFlag } from '../../lib/command-framework/flags.js';
67
import { tryToGetKeyValueStore } from '../../lib/commands/storages.js';
78
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
89
import { error, info, success } from '../../lib/outputs.js';
@@ -20,8 +21,13 @@ export class KeyValueStoresRmCommand extends ApifyCommand<typeof KeyValueStoresR
2021
}),
2122
};
2223

24+
static override flags = {
25+
...YesFlag,
26+
};
27+
2328
async run() {
2429
const { keyValueStoreNameOrId } = this.args;
30+
const { yes } = this.flags;
2531

2632
const client = await getLoggedClientOrThrow();
2733

@@ -37,6 +43,7 @@ export class KeyValueStoresRmCommand extends ApifyCommand<typeof KeyValueStoresR
3743

3844
const confirmed = await useYesNoConfirm({
3945
message: `Are you sure you want to delete this Key-value store?`,
46+
providedConfirmFromStdin: yes || undefined,
4047
});
4148

4249
if (!confirmed) {

src/commands/runs/rm.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ACTOR_JOB_STATUSES } from '@apify/consts';
44

55
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
66
import { Args } from '../../lib/command-framework/args.js';
7+
import { YesFlag } from '../../lib/command-framework/flags.js';
78
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
89
import { error, info, success } from '../../lib/outputs.js';
910
import { getLoggedClientOrThrow } from '../../lib/utils.js';
@@ -27,8 +28,13 @@ export class RunsRmCommand extends ApifyCommand<typeof RunsRmCommand> {
2728
}),
2829
};
2930

31+
static override flags = {
32+
...YesFlag,
33+
};
34+
3035
async run() {
3136
const { runId } = this.args;
37+
const { yes } = this.flags;
3238

3339
const apifyClient = await getLoggedClientOrThrow();
3440

@@ -49,6 +55,7 @@ export class RunsRmCommand extends ApifyCommand<typeof RunsRmCommand> {
4955

5056
const confirmedDelete = await useYesNoConfirm({
5157
message: `Are you sure you want to delete this Actor Run?`,
58+
providedConfirmFromStdin: yes || undefined,
5259
});
5360

5461
if (!confirmedDelete) {

src/lib/command-framework/flags.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ export const Flags = {
6464
integer: integerFlag,
6565
};
6666

67+
/** Reusable `--yes` / `-y` flag for commands with confirmation prompts. */
68+
export const YesFlag = {
69+
yes: Flags.boolean({
70+
char: 'y',
71+
description: 'Automatic yes to prompts; assume "yes" as answer to all prompts.',
72+
default: false,
73+
}),
74+
};
75+
6776
function stringFlag<const Choices extends string[], const T extends StringFlagOptions<readonly string[]>>(
6877
options: T & { choices?: Choices },
6978
): TaggedFlagBuilder<'string', Choices, T['default'] extends string ? true : T['required'], T['default']> {

test/e2e/commands/builds/create-info-ls.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('[e2e][api] builds namespace', () => {
4545
const me = await client.user('me').get();
4646
await client.actor(`${me.username}/${actor.name}`).delete();
4747
} catch {
48-
// Best-effort cleanup
48+
// Do nothing
4949
}
5050
}
5151

0 commit comments

Comments
 (0)