skysync-cli
Version:
SkySync Command Line Interface
66 lines (65 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 command_1 = require("../../util/command");
const util_1 = require("./util");
const jobTemplateKinds = [
'folder_mapping',
'personal_drive',
'transfer',
];
function isJobTemplateKindValid(jobTemplateKind) {
if (jobTemplateKinds.indexOf(jobTemplateKind) > -1) {
return true;
}
return false;
}
function getJobTemplatesJson(argv) {
return argv.templates && argv.templates.split(',').map(input => {
const jobTemplateKindDefault = 'transfer';
const [jobTemplateId, jobTemplateKind = jobTemplateKindDefault] = input.split(':');
return {
id: jobTemplateId,
kind: isJobTemplateKindValid(jobTemplateKind) ? jobTemplateKind : jobTemplateKindDefault
};
}).filter(x => x != null) || [];
}
module.exports = {
command: 'add <name>',
desc: 'Add new profile',
builder: yargs => {
yargs.options({
'description': {
desc: 'Profile description.',
type: 'string'
},
'instructions': {
desc: 'Profile instructions',
type: 'string'
},
'templates': {
desc: 'A comma separated list of the job templates to associate to this new profile. Both the ID and kind of the job template must be specified (ie. 123456:transfer).',
type: 'string'
}
});
},
handler: argv => {
command_1.runCommand(argv, (client, output) => __awaiter(void 0, void 0, void 0, function* () {
const newProfileRequestBody = {
name: argv.name,
description: argv.description,
instructions: argv.instructions,
job_templates: getJobTemplatesJson(argv)
};
const profile = yield client.profiles.add(newProfileRequestBody, { generateclient: true });
output.writeItem(profile, util_1.outputFormat);
}));
}
};