UNPKG

skysync-cli

Version:

SkySync Command Line Interface

65 lines (64 loc) 2.96 kB
"use strict"; 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: 'update', description: 'Update bandwidth throttle', builder: yargs => { yargs.options({ 'upload': { alias: 'u', desc: 'The throttle options for uploads.', type: 'string' }, 'upload-file': { alias: 'uf', desc: 'The options JSON file', type: 'string' }, 'download': { alias: 'd', desc: 'The throttle options for downloads.', type: 'string' }, 'download-file': { alias: 'df', desc: 'The options JSON file', type: 'string' } }).check(argv => { if (argv.hasOwnProperty('upload') || argv.hasOwnProperty('upload-file') || argv.hasOwnProperty('download') || argv.hasOwnProperty('download-file')) { return true; } return 'Must include at least one option.'; }); }, handler: argv => { command_1.runCommand(argv, (client, output) => __awaiter(void 0, void 0, void 0, function* () { let performance = {}; if (argv.hasOwnProperty('upload') || argv.hasOwnProperty('upload-file')) { performance.upload = argv.upload ? JSON.parse(argv.upload) : undefined; if (!performance.upload && argv.uploadFile) { performance.upload = JSON.parse(fs.readFileSync(argv.uploadFile, 'utf-8')); } } if (argv.hasOwnProperty('download') || argv.hasOwnProperty('download-file')) { performance.download = argv.download ? JSON.parse(argv.download) : undefined; if (!performance.download && argv.downloadFile) { performance.download = JSON.parse(fs.readFileSync(argv.downloadFile, 'utf-8')); } } util_1.writeConfiguration(yield client.performance.post(performance), output); })); } };