skysync-cli
Version:
SkySync Command Line Interface
68 lines (67 loc) • 3.08 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: 'start [id]',
desc: 'Start job(s)',
builder: yargs => {
yargs.options(Object.assign({ 'all': {
desc: 'Start all jobs',
type: 'boolean',
group: 'Search',
default: undefined
} }, util_2.jobsSearchArgumentsDefault));
},
handler: argv => {
if (argv.id === undefined) {
if (util_2.searchCriteriaIsMissing(argv)) {
console.error('Search criteria must be specified. To start all jobs, use --all parameter'.red);
}
else {
command_1.runCommand(argv, (client, output) => __awaiter(void 0, void 0, void 0, function* () {
const result = yield client.jobs.startMultiple(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 jobs were started because no jobs matched the specified filter');
}
else if (totalCount === 1) {
output.writeSuccess('1 job started');
}
else {
output.writeSuccess(`${totalCount} jobs started`);
}
}));
}
}
else {
command_1.runCommand(argv, (client, output) => __awaiter(void 0, void 0, void 0, function* () {
const job = yield client.jobs.start(argv.id, {
fields: [
'name',
'status',
'disabled'
]
});
if (job == null) {
output.writeFailure(`Job with ID=${argv.id} was not found`);
}
else {
output.writeItem(job, util_2.detailOutputFormat);
}
}));
}
}
};