Skip to content

Commit

Permalink
chore: post rebase cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vladfrangu committed Sep 9, 2024
1 parent bacc80e commit f891cce
Showing 1 changed file with 3 additions and 133 deletions.
136 changes: 3 additions & 133 deletions src/commands/runs/ls.ts
Original file line number Diff line number Diff line change
@@ -1,143 +1,13 @@
import { Flags } from '@oclif/core';
import { DurationFormatter as SapphireDurationFormatter, TimeTypes } from '@sapphire/duration';
import { Timestamp } from '@sapphire/timestamp';
import chalk from 'chalk';
import Table from 'cli-table';

import { ApifyCommand } from '../../lib/apify_command.js';
import { prettyPrintStatus } from '../../lib/commands/pretty-print-status.js';
import { resolveActorContext } from '../../lib/commands/resolve-actor-context.js';
import { error, simpleLog } from '../../lib/outputs.js';
import { getLocalConfig, getLocalUserInfo, getLoggedClientOrThrow } from '../../lib/utils.js';

// TODO: remove this once https://github.com/apify/apify-cli/pull/620 is merged
async function resolveActorContext({
providedActorNameOrId,
client,
}: { providedActorNameOrId: string | undefined; client: import('apify-client').ApifyClient }) {
const userInfo = await getLocalUserInfo();
const usernameOrId = userInfo.username || (userInfo.id as string);
const localConfig = getLocalConfig(process.cwd()) || {};

// Full ID
if (providedActorNameOrId?.includes('/')) {
const actor = await client.actor(providedActorNameOrId).get();
if (!actor) {
return {
valid: false as const,
reason: `Actor with ID "${providedActorNameOrId}" was not found`,
};
}

return {
valid: true as const,
userFriendlyId: `${actor.username}/${actor.name}`,
id: actor.id,
};
}

// Try fetching Actor directly by name/id
if (providedActorNameOrId) {
const actorById = await client.actor(providedActorNameOrId).get();

if (actorById) {
return {
valid: true as const,
userFriendlyId: `${actorById.username}/${actorById.name}`,
id: actorById.id,
};
}

const actorByName = await client.actor(`${usernameOrId}/${providedActorNameOrId.toLowerCase()}`).get();

if (actorByName) {
return {
valid: true as const,
userFriendlyId: `${actorByName.username}/${actorByName.name}`,
id: actorByName.id,
};
}

return {
valid: false as const,
reason: `Actor with name or ID "${providedActorNameOrId}" was not found`,
};
}

if (localConfig.name) {
const actor = await client.actor(`${usernameOrId}/${localConfig.name}`).get();

if (!actor) {
return {
valid: false as const,
reason: `Actor with name "${localConfig.name}" was not found`,
};
}

return {
valid: true as const,
userFriendlyId: `${actor.username}/${actor.name}`,
id: actor.id,
};
}

return {
valid: false as const,
reason: 'Unable to detect what Actor to create a build for',
};
}

function prettyPrintStatus(status: string) {
switch (status) {
case 'READY':
return chalk.green('Ready');
case 'RUNNING':
return chalk.blue('Running');
case 'SUCCEEDED':
return chalk.green('Succeeded');
case 'FAILED':
return chalk.red('Failed');
case 'ABORTING':
return chalk.yellow('Aborting');
case 'ABORTED':
return chalk.red('Aborted');
case 'TIMING-OUT':
return chalk.yellow('Timing Out');
case 'TIMED-OUT':
return chalk.red('Timed Out');
default:
return chalk.gray(
(status as string)
.split('-')
.map((part) => part[0].toUpperCase() + part.slice(1).toLowerCase())
.join(' '),
);
}
}

const ShortDurationFormatter = new SapphireDurationFormatter({
[TimeTypes.Day]: {
DEFAULT: 'd',
},
[TimeTypes.Hour]: {
DEFAULT: 'h',
},
[TimeTypes.Minute]: {
DEFAULT: 'm',
},
[TimeTypes.Month]: {
DEFAULT: 'M',
},
[TimeTypes.Second]: {
DEFAULT: 's',
},
[TimeTypes.Week]: {
DEFAULT: 'w',
},
[TimeTypes.Year]: {
DEFAULT: 'y',
},
});

// END of TODO
import { getLoggedClientOrThrow, ShortDurationFormatter } from '../../lib/utils.js';

const multilineTimestampFormatter = new Timestamp(`YYYY-MM-DD[\n]HH:mm:ss`);
const terminalColumns = process.stdout.columns ?? 100;
Expand Down

0 comments on commit f891cce

Please sign in to comment.