UNPKG

skysync-cli

Version:

SkySync Command Line Interface

89 lines (88 loc) 3.08 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 outputFormat = { table: [ { header: 'ID', property: 'id' }, { header: 'Name', property: 'name' }, { header: 'Platform', property: 'platform.name' }, { header: 'Enabled', property: 'disabled', transform: val => !val } ], json: [ 'platform.id' ] }; module.exports = { command: 'add', desc: 'Add new connection', builder: yargs => { yargs.options({ 'platform': { alias: 'p', desc: 'Storage platform', type: 'string', demand: true }, 'name': { desc: 'Connection name', type: 'string' }, 'auth-input': { alias: 'in', desc: 'Read authentication JSON from stdin', type: 'boolean' }, 'auth-file': { alias: 'file', desc: 'The authentication JSON file', type: 'string' } }); }, handler: argv => { command_1.runCommand(argv, (client, output) => __awaiter(void 0, void 0, void 0, function* () { let authJson = argv.authInput ? yield command_1.readJsonInput() : undefined; if (!authJson && argv.authFile) { authJson = JSON.parse(fs.readFileSync(argv.authFile, 'utf-8')); } if (authJson) { const connection = { name: argv.name, platform: { id: argv.platform }, auth: authJson }; const result = yield client.connections.add(connection); output.writeItem(result, outputFormat); return; } const request = yield client.connections.authorize(argv.platform, { name: argv.name }); output.writeSuccess(`Create the connection using your browser: ${request.target}`, true); })); } };