jamsocket
Version:
A CLI for the Jamsocket platform
70 lines (69 loc) • 3.16 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const jamsocket_1 = require("../../jamsocket");
const inquirer = tslib_1.__importStar(require("inquirer"));
const date_fns_1 = require("date-fns");
const formatting_1 = require("../../lib/formatting");
const core_2 = require("@oclif/core");
class Delete extends core_1.Command {
async run() {
const { args, flags } = await this.parse(Delete);
const jamsocket = jamsocket_1.Jamsocket.fromEnvironment();
const serviceInfo = await jamsocket.serviceInfo(args.service);
const lastImgUpload = serviceInfo.last_image_upload_time
? (0, date_fns_1.formatDistanceToNow)(new Date(serviceInfo.last_image_upload_time))
: null;
const lastSpawn = serviceInfo.last_spawned_at
? (0, date_fns_1.formatDistanceToNow)(new Date(serviceInfo.last_spawned_at))
: null;
const formattedInfo = [
'The service',
(0, formatting_1.lightBlue)(serviceInfo.name),
lastImgUpload === null
? 'has ' + (0, formatting_1.lightMagenta)('no container images') + ','
: 'had a ' + (0, formatting_1.lightMagenta)(`container image pushed to it ${lastImgUpload} ago`) + ',',
lastSpawn === null
? 'and has ' + (0, formatting_1.lightMagenta)('never been spawned') + '.'
: 'and was ' + (0, formatting_1.lightMagenta)(`last spawned ${lastSpawn} ago`) + '.',
].filter(Boolean);
this.log();
this.log(formattedInfo.join(' '));
this.log(`(For more information about this service, run \`jamsocket service info ${serviceInfo.name}\`.)\n`);
if (!flags.yes) {
const response = await inquirer.prompt([
{
name: 'confirmDelete',
message: 'Are you sure you want to delete this service? This action cannot be undone!',
type: 'list',
choices: [{ name: 'no' }, { name: 'yes' }],
},
]);
if (response.confirmDelete !== 'yes') {
this.log('Service deletion canceled.');
return;
}
this.log();
const userInput = await core_1.CliUx.ux.prompt(`Type the service name (${serviceInfo.name}) to delete it. (Anything else will abort.)`, {
required: false,
});
if (userInput.trim() !== serviceInfo.name) {
this.log('Input does not match service name. Service deletion canceled.');
return;
}
}
await jamsocket.serviceDelete(args.service);
this.log(`Deleted service: ${args.service}`);
}
}
Delete.description = 'Deletes a service';
Delete.examples = ['<%= config.bin %> <%= command.id %> my-service'];
Delete.args = [{ name: 'service', required: true }];
Delete.flags = {
yes: core_2.Flags.boolean({
char: 'y',
description: 'Skip confirmation prompt',
}),
};
exports.default = Delete;
;