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
7 changes: 7 additions & 0 deletions src/commands/actors/rm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ApifyApiError } from 'apify-client';

import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
import { Args } from '../../lib/command-framework/args.js';
import { YesFlag } from '../../lib/command-framework/flags.js';
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
import { error, info, success } from '../../lib/outputs.js';
import { getLoggedClientOrThrow } from '../../lib/utils.js';
Expand Down Expand Up @@ -32,8 +33,13 @@ export class ActorsRmCommand extends ApifyCommand<typeof ActorsRmCommand> {
}),
};

static override flags = {
...YesFlag,
};

async run() {
const { actorId } = this.args;
const { yes } = this.flags;

const apifyClient = await getLoggedClientOrThrow();

Expand All @@ -46,6 +52,7 @@ export class ActorsRmCommand extends ApifyCommand<typeof ActorsRmCommand> {

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

if (!confirmedDelete) {
Expand Down
8 changes: 2 additions & 6 deletions src/commands/builds/remove-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ActorTaggedBuild, ApifyApiError } from 'apify-client';
import chalk from 'chalk';

import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
import { Flags } from '../../lib/command-framework/flags.js';
import { Flags, YesFlag } from '../../lib/command-framework/flags.js';
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
import { error, info, success } from '../../lib/outputs.js';
import { getLoggedClientOrThrow } from '../../lib/utils.js';
Expand Down Expand Up @@ -36,11 +36,7 @@ export class BuildsRemoveTagCommand extends ApifyCommand<typeof BuildsRemoveTagC
description: 'The tag to remove from the build.',
required: true,
}),
yes: Flags.boolean({
char: 'y',
description: 'Automatic yes to prompts; assume "yes" as answer to all prompts.',
default: false,
}),
...YesFlag,
};

async run() {
Expand Down
26 changes: 21 additions & 5 deletions src/commands/builds/rm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ActorTaggedBuild, ApifyApiError } from 'apify-client';

import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
import { Args } from '../../lib/command-framework/args.js';
import { YesFlag } from '../../lib/command-framework/flags.js';
import { useInputConfirmation } from '../../lib/hooks/user-confirmations/useInputConfirmation.js';
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
import { error, info, success } from '../../lib/outputs.js';
Expand Down Expand Up @@ -33,8 +34,13 @@ export class BuildsRmCommand extends ApifyCommand<typeof BuildsRmCommand> {
}),
};

static override flags = {
...YesFlag,
};

async run() {
const { buildId } = this.args;
const { yes } = this.flags;

const apifyClient = await getLoggedClientOrThrow();

Expand All @@ -60,11 +66,21 @@ export class BuildsRmCommand extends ApifyCommand<typeof BuildsRmCommand> {
}

// 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.
const confirmed = await (confirmationPrompt ? useInputConfirmation : useYesNoConfirm)({
message: `Are you sure you want to delete this Actor Build?${confirmationPrompt ? ` If so, please type in "${confirmationPrompt}":` : ''}`,
expectedValue: confirmationPrompt ?? '',
failureMessage: 'Your provided value does not match the build tag.',
});
let confirmed: string | boolean;

if (confirmationPrompt) {
confirmed = await useInputConfirmation({
message: `Are you sure you want to delete this Actor Build? If so, please type in "${confirmationPrompt}":`,
expectedValue: confirmationPrompt,
failureMessage: 'Your provided value does not match the build tag.',
providedConfirmFromStdin: yes ? confirmationPrompt : undefined,
});
} else {
confirmed = await useYesNoConfirm({
message: `Are you sure you want to delete this Actor Build?`,
providedConfirmFromStdin: yes || undefined,
});
}

if (!confirmed) {
info({
Expand Down
7 changes: 7 additions & 0 deletions src/commands/datasets/rm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import chalk from 'chalk';

import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
import { Args } from '../../lib/command-framework/args.js';
import { YesFlag } from '../../lib/command-framework/flags.js';
import { tryToGetDataset } from '../../lib/commands/storages.js';
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
import { error, info, success } from '../../lib/outputs.js';
Expand Down Expand Up @@ -34,8 +35,13 @@ export class DatasetsRmCommand extends ApifyCommand<typeof DatasetsRmCommand> {
}),
};

static override flags = {
...YesFlag,
};

async run() {
const { datasetNameOrId } = this.args;
const { yes } = this.flags;

const client = await getLoggedClientOrThrow();

Expand All @@ -51,6 +57,7 @@ export class DatasetsRmCommand extends ApifyCommand<typeof DatasetsRmCommand> {

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

if (!confirmed) {
Expand Down
9 changes: 2 additions & 7 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import process from 'node:process';

import { ApifyCommand } from '../lib/command-framework/apify-command.js';
import { Args } from '../lib/command-framework/args.js';
import { Flags } from '../lib/command-framework/flags.js';
import { Flags, YesFlag } from '../lib/command-framework/flags.js';
import { CommandExitCodes, DEFAULT_LOCAL_STORAGE_DIR, EMPTY_LOCAL_CONFIG, LOCAL_CONFIG_PATH } from '../lib/consts.js';
import { useActorConfig } from '../lib/hooks/useActorConfig.js';
import { ProjectLanguage, useCwdProject } from '../lib/hooks/useCwdProject.js';
Expand Down Expand Up @@ -55,12 +55,7 @@ export class InitCommand extends ApifyCommand<typeof InitCommand> {
};

static override flags = {
yes: Flags.boolean({
char: 'y',
description:
'Automatic yes to prompts; assume "yes" as answer to all prompts. Note that in some cases, the command may still ask for confirmation.',
required: false,
}),
...YesFlag,
dockerfile: Flags.string({
description: 'Path to a Dockerfile to use for the Actor (e.g., "./Dockerfile" or "./docker/Dockerfile").',
required: false,
Expand Down
7 changes: 7 additions & 0 deletions src/commands/key-value-stores/delete-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import chalk from 'chalk';

import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
import { Args } from '../../lib/command-framework/args.js';
import { YesFlag } from '../../lib/command-framework/flags.js';
import { tryToGetKeyValueStore } from '../../lib/commands/storages.js';
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
import { error, info } from '../../lib/outputs.js';
Expand Down Expand Up @@ -38,8 +39,13 @@ export class KeyValueStoresDeleteValueCommand extends ApifyCommand<typeof KeyVal
}),
};

static override flags = {
...YesFlag,
};

async run() {
const { storeId, itemKey } = this.args;
const { yes } = this.flags;

const apifyClient = await getLoggedClientOrThrow();
const maybeStore = await tryToGetKeyValueStore(apifyClient, storeId);
Expand All @@ -65,6 +71,7 @@ export class KeyValueStoresDeleteValueCommand extends ApifyCommand<typeof KeyVal

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

if (!confirm) {
Expand Down
7 changes: 7 additions & 0 deletions src/commands/key-value-stores/rm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import chalk from 'chalk';

import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
import { Args } from '../../lib/command-framework/args.js';
import { YesFlag } from '../../lib/command-framework/flags.js';
import { tryToGetKeyValueStore } from '../../lib/commands/storages.js';
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
import { error, info, success } from '../../lib/outputs.js';
Expand Down Expand Up @@ -34,8 +35,13 @@ export class KeyValueStoresRmCommand extends ApifyCommand<typeof KeyValueStoresR
}),
};

static override flags = {
...YesFlag,
};

async run() {
const { keyValueStoreNameOrId } = this.args;
const { yes } = this.flags;

const client = await getLoggedClientOrThrow();

Expand All @@ -51,6 +57,7 @@ export class KeyValueStoresRmCommand extends ApifyCommand<typeof KeyValueStoresR

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

if (!confirmed) {
Expand Down
7 changes: 7 additions & 0 deletions src/commands/runs/rm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ACTOR_JOB_STATUSES } from '@apify/consts';

import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
import { Args } from '../../lib/command-framework/args.js';
import { YesFlag } from '../../lib/command-framework/flags.js';
import { useYesNoConfirm } from '../../lib/hooks/user-confirmations/useYesNoConfirm.js';
import { error, info, success } from '../../lib/outputs.js';
import { getLoggedClientOrThrow } from '../../lib/utils.js';
Expand Down Expand Up @@ -41,8 +42,13 @@ export class RunsRmCommand extends ApifyCommand<typeof RunsRmCommand> {
}),
};

static override flags = {
...YesFlag,
};

async run() {
const { runId } = this.args;
const { yes } = this.flags;

const apifyClient = await getLoggedClientOrThrow();

Expand All @@ -63,6 +69,7 @@ export class RunsRmCommand extends ApifyCommand<typeof RunsRmCommand> {

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

if (!confirmedDelete) {
Expand Down
9 changes: 9 additions & 0 deletions src/lib/command-framework/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ export const Flags = {
integer: integerFlag,
};

/** Reusable `--yes` / `-y` flag for commands with confirmation prompts. */
export const YesFlag = {
yes: Flags.boolean({
char: 'y',
description: 'Automatic yes to prompts; assume "yes" as answer to all prompts.',
default: false,
}),
};

function stringFlag<const Choices extends string[], const T extends StringFlagOptions<readonly string[]>>(
options: T & { choices?: Choices },
): TaggedFlagBuilder<'string', Choices, T['default'] extends string ? true : T['required'], T['default']> {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/commands/builds/create-info-ls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('[e2e][api] builds namespace', () => {
const me = await client.user('me').get();
await client.actor(`${me.username}/${actor.name}`).delete();
} catch {
// Best-effort cleanup
// Do nothing
}
}

Expand Down
Loading