skysync-cli
Version:
SkySync Command Line Interface
61 lines (60 loc) • 2.93 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
const command_1 = require("../../util/command");
const util_1 = require("../util");
const util_2 = require("./util");
module.exports = {
command: 'pause [id]',
desc: 'Pause job scheduler(s)',
builder: yargs => {
yargs.options(Object.assign({ 'all': {
desc: 'Pause all job schedulers',
type: 'boolean',
group: 'Search',
default: undefined
} }, util_2.schedulersSearchArgumentsDefault));
},
handler: argv => {
if (argv.id === undefined) {
if (util_2.searchCriteriaIsMissing(argv)) {
console.error('Search criteria must be specified. To pause all job schedulers, use --all parameter'.red);
}
else {
command_1.runCommand(argv, (client, output) => __awaiter(void 0, void 0, void 0, function* () {
const result = yield client.jobSchedulers.pauseMultiple(Object.assign({}, util_2.getSearchArgs(argv)));
const totalCount = result.meta.total_count;
if (argv.json) {
output.writeItem(util_1.formatTotalCount(totalCount));
}
else if (totalCount === undefined || totalCount === 0) {
output.writeWarning('Warning: 0 job schedulers were paused because no job schedulers matched the specified filter');
}
else {
output.writeSuccess(`${totalCount} job scheduler(s) paused`);
}
}));
}
}
else {
command_1.runCommand(argv, (client, output) => __awaiter(void 0, void 0, void 0, function* () {
const jobScheduler = yield client.jobSchedulers.pause(argv.id, {
fields: 'all'
});
if (jobScheduler == null) {
output.writeFailure(`Job scheduler with ID=${argv.id} was not found`);
}
else {
output.writeItem(jobScheduler, util_2.outputFormat);
}
}));
}
}
};