skysync-cli
Version:
SkySync Command Line Interface
70 lines (69 loc) • 2.74 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 template',
builder: yargs => {
yargs.options({
'kind': {
desc: 'The job template kind',
type: 'string',
default: 'transfer',
demand: true
},
'name': {
desc: 'The job template name',
type: 'string'
},
'auto': {
desc: 'Schedule the job as automatic',
type: 'boolean'
},
'manual': {
desc: 'Schedule the job as manual',
type: 'boolean'
},
'options-input': {
alias: 'in',
desc: 'Read JSON options from stdin',
type: 'boolean'
},
'options-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 template = {
kind: argv.kind,
name: argv.name,
schedule: {
mode: argv.manual ? 'manual' : 'auto'
}
};
let options = argv.optionsInput ? yield command_1.readJsonInput() : undefined;
if (!options && argv.optionsFile) {
options = JSON.parse(fs.readFileSync(argv.optionsFile, 'utf-8'));
}
template[template.kind] = options;
template = yield client.templates.add(template, {
fields: ['id', 'name', 'kind', 'disabled', 'schedule', 'transfer']
});
output.writeItem(template, util_1.detailOutputFormat);
}));
}
};