Skip to content

Commit

Permalink
feat: print full ref as bold
Browse files Browse the repository at this point in the history
  • Loading branch information
mo4islona committed Sep 9, 2024
1 parent 30751a0 commit 9361f09
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { isNil, uniqBy } from 'lodash';

import { ApiError, getOrganization, getSquid, listOrganizations, listUserSquids, SquidRequest } from './api';
import { getTTY } from './tty';
import { parseSquidFullname } from './utils';

export const SUCCESS_CHECK_MARK = chalk.green('✓');

Expand Down
28 changes: 19 additions & 9 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { deploySquid, OrganizationRequest, Squid, uploadFile } from '../api';
import { SqdFlags, SUCCESS_CHECK_MARK } from '../command';
import { DeployCommand } from '../deploy-command';
import { loadManifestFile } from '../manifest';
import { formatSquidFullname, ParsedSquidFullname, parseSquidFullname } from '../utils';
import { formatSquidFullname, ParsedSquidFullname, parseSquidFullname, printSquidFullname } from '../utils';

const compressAsync = promisify(targz.compress);

Expand Down Expand Up @@ -188,10 +188,6 @@ export default class Deploy extends DeployCommand {

const { buildDir, squidDir, manifest } = res;

this.log(chalk.dim(`Squid directory: ${squidDir}`));
this.log(chalk.dim(`Build directory: ${buildDir}`));
this.log(chalk.dim(`Manifest: ${manifestPath}`));

const overrides = fullname ? fullname : flags;

// some hack to add slot name in case if version is used
Expand All @@ -210,6 +206,20 @@ export default class Deploy extends DeployCommand {

name = await this.promptSquidName(name);

this.log(chalk.dim(`Squid directory: ${squidDir}`));
this.log(chalk.dim(`Build directory: ${buildDir}`));
this.log(chalk.dim(`Manifest: ${manifestPath}`));
this.log(chalk.cyan(`-----------------------------`));
this.log(chalk.cyan(`Organization: ${organization.code}`));
this.log(chalk.cyan(`Squid name: ${name}`));
if (slot) {
this.log(chalk.cyan(`Squid slot: ${slot}`));
}
if (tag) {
this.log(chalk.cyan(`Squid tag: ${tag}`));
}
this.log(chalk.cyan(`-----------------------------`));

let target: Squid | null = null;
if (slot || tag) {
target = await this.findSquid({
Expand Down Expand Up @@ -266,7 +276,7 @@ export default class Deploy extends DeployCommand {
if (target) {
this.logDeployResult(
UPDATE_COLOR,
`The squid ${formatSquidFullname({
`The squid ${printSquidFullname({
org: deployment.organization.code,
name: deployment.squid.name,
slot: deployment.squid.slot,
Expand All @@ -275,7 +285,7 @@ export default class Deploy extends DeployCommand {
} else {
this.logDeployResult(
CREATE_COLOR,
`A new squid ${formatSquidFullname({
`A new squid ${printSquidFullname({
org: deployment.organization.code,
name: deployment.squid.name,
slot: deployment.squid.slot,
Expand All @@ -295,7 +305,7 @@ export default class Deploy extends DeployCommand {
type: 'confirm',
message: [
chalk.reset(
`A squid "${formatSquidFullname({
`A squid "${printSquidFullname({
org: target.organization.code,
name: target.name,
slot: target.slot,
Expand Down Expand Up @@ -323,7 +333,7 @@ export default class Deploy extends DeployCommand {
type: 'confirm',
message: [
chalk.reset(
`A squid tag "${tag}" has already been assigned to ${formatSquidFullname({ name: oldSquid.name, slot: oldSquid.slot })}.`,
`A squid tag "${tag}" has already been assigned to ${printSquidFullname({ name: oldSquid.name, slot: oldSquid.slot })}.`,
),
chalk.reset(`The tag will be assigned to the newly created squid. ${chalk.bold('Are you sure?')}`),
].join('\n'),
Expand Down
4 changes: 2 additions & 2 deletions src/commands/restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isNil, omitBy } from 'lodash';
import { restartSquid } from '../api';
import { SqdFlags } from '../command';
import { DeployCommand } from '../deploy-command';
import { formatSquidFullname } from '../utils';
import { formatSquidFullname, printSquidFullname } from '../utils';

import { UPDATE_COLOR } from './deploy';

Expand Down Expand Up @@ -66,7 +66,7 @@ export default class Restart extends DeployCommand {

this.logDeployResult(
UPDATE_COLOR,
`The squid ${formatSquidFullname({
`The squid ${printSquidFullname({
org: deployment.organization.code,
name: deployment.squid.name,
slot: deployment.squid.slot,
Expand Down
6 changes: 3 additions & 3 deletions src/commands/rm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import inquirer from 'inquirer';
import { deleteSquid } from '../api';
import { SqdFlags, SquidReferenceArg } from '../command';
import { DeployCommand } from '../deploy-command';
import { formatSquidFullname } from '../utils';
import { formatSquidFullname, printSquidFullname } from '../utils';

import { DELETE_COLOR } from './deploy';

Expand Down Expand Up @@ -74,7 +74,7 @@ export default class Rm extends DeployCommand {
{
name: 'confirm',
type: 'confirm',
message: `Your squid ${formatSquidFullname({ org, name, slot: squid.slot })} will be completely removed. This action can not be undone. Are you sure?`,
message: `Your squid ${printSquidFullname({ org, name, slot: squid.slot })} will be completely removed. This action can not be undone. Are you sure?`,
},
]);
if (!confirm) return;
Expand All @@ -86,7 +86,7 @@ export default class Rm extends DeployCommand {

this.logDeployResult(
DELETE_COLOR,
`A squid deployment ${formatSquidFullname({
`A squid deployment ${printSquidFullname({
org: deployment.organization.code,
name: deployment.squid.name,
slot: deployment.squid.slot,
Expand Down
8 changes: 4 additions & 4 deletions src/commands/tags/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import inquirer from 'inquirer';
import { addSquidTag } from '../../api';
import { SqdFlags } from '../../command';
import { DeployCommand } from '../../deploy-command';
import { formatSquidFullname } from '../../utils';
import { formatSquidFullname, printSquidFullname } from '../../utils';
import { UPDATE_COLOR } from '../deploy';

export default class Add extends DeployCommand {
Expand Down Expand Up @@ -70,7 +70,7 @@ export default class Add extends DeployCommand {

if (squid.tags.find((t) => t.name === tagName)) {
return this.log(
`Tag "${tagName}" is already assigned to the squid ${formatSquidFullname({ org, name, tag, slot })}`,
`Tag "${tagName}" is already assigned to the squid ${printSquidFullname({ org, name, tag, slot })}`,
);
}

Expand All @@ -82,7 +82,7 @@ export default class Add extends DeployCommand {
type: 'confirm',
message: [
chalk.reset(
`A squid tag "${tagName}" has already been assigned to the previous squid deployment ${formatSquidFullname({ org, name, slot: oldSquid.slot })}.`,
`A squid tag "${tagName}" has already been assigned to the previous squid deployment ${printSquidFullname({ org, name, slot: oldSquid.slot })}.`,
),
chalk.reset(`The tag URL will be assigned to the newly created deployment. ${chalk.bold(`Are you sure?`)}`),
].join('\n'),
Expand All @@ -101,7 +101,7 @@ export default class Add extends DeployCommand {

this.logDeployResult(
UPDATE_COLOR,
`The squid ${formatSquidFullname({
`The squid ${printSquidFullname({
org: deployment.organization.code,
name: deployment.squid.name,
slot: deployment.squid.slot,
Expand Down
6 changes: 3 additions & 3 deletions src/commands/tags/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Args } from '@oclif/core';
import { removeSquidTag } from '../../api';
import { SqdFlags } from '../../command';
import { DeployCommand } from '../../deploy-command';
import { formatSquidFullname } from '../../utils';
import { formatSquidFullname, printSquidFullname } from '../../utils';
import { UPDATE_COLOR } from '../deploy';

export default class Remove extends DeployCommand {
Expand Down Expand Up @@ -74,7 +74,7 @@ export default class Remove extends DeployCommand {
const squid = await this.findOrThrowSquid({ organization, reference });

if (!squid.tags.some((t) => t.name === tagName)) {
return this.log(`Tag "${tagName}" is not assigned to the squid ${formatSquidFullname({ org, name, tag, slot })}`);
return this.log(`Tag "${tagName}" is not assigned to the squid ${printSquidFullname({ org, name, tag, slot })}`);
}

const deployment = await removeSquidTag({
Expand All @@ -87,7 +87,7 @@ export default class Remove extends DeployCommand {

this.logDeployResult(
UPDATE_COLOR,
`The squid ${formatSquidFullname({
`The squid ${printSquidFullname({
org: deployment.organization.code,
name: deployment.squid.name,
slot: deployment.squid.slot,
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export function formatSquidFullname({ org, name, slot, tag }: ParsedSquidFullnam
return res;
}

export function printSquidFullname(args: ParsedSquidFullname) {
return chalk.bold(formatSquidFullname(args));
}

export const SQUID_FULLNAME_REGEXP = /^(([a-z0-9\-]+)\/)?([a-z0-9\-]+)([:@])([a-z0-9\-]+)$/;

export function parseSquidFullname(fullname: string): ParsedSquidFullname {
Expand Down

0 comments on commit 9361f09

Please sign in to comment.