skysync-cli
Version:
SkySync Command Line Interface
70 lines (69 loc) • 2.84 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 fs = require("fs");
const command_1 = require("../../util/command");
const util_1 = require("./util");
module.exports = {
command: 'add',
desc: 'Add job',
builder: yargs => {
yargs.options({
'kind': {
desc: 'The job kind',
type: 'string'
},
'name': {
desc: 'The job name',
type: 'string'
},
'auto': {
desc: 'Schedule the job as automatic',
type: 'boolean'
},
'manual': {
desc: 'Schedule the job as manual',
type: 'boolean'
},
'job-input': {
alias: 'in',
desc: 'Read JSON options from stdin',
type: 'boolean'
},
'job-file': {
alias: 'file',
desc: 'The options JSON file',
type: 'string'
}
});
},
handler: argv => {
command_1.runCommand(argv, (client, output) => __awaiter(void 0, void 0, void 0, function* () {
let jobCliParameters = Object.assign(Object.assign(Object.assign({}, argv.kind && { kind: argv.kind }), argv.name && { name: argv.name }), argv.manual && { schedule: { mode: 'manual' } });
let jobParametersInput = argv.jobInput ? yield command_1.readJsonInput() : undefined;
if (!jobParametersInput && argv.jobFile) {
jobParametersInput = JSON.parse(fs.readFileSync(argv.jobFile, 'utf-8'));
}
let jobDefaults = {
kind: 'transfer',
schedule: { mode: 'auto' }
};
let job = Object.assign(jobDefaults, jobParametersInput, jobCliParameters);
job = yield client.jobs.add(job, {
fields: [
'name',
'status',
'disabled'
]
});
output.writeItem(job, util_1.detailOutputFormat);
}));
}
};