UNPKG

skysync-cli

Version:

SkySync Command Line Interface

97 lines (96 loc) 3.44 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 command_1 = require("../../util/command"); const outputFormat = { table: [ { header: 'Items', property: 'item_stats.items.count' }, { header: 'Bytes', property: 'item_stats.items.bytes' }, { header: 'Containers', property: 'item_stats.containers.count' } ] }; function isEmpty(str) { return (!str || str.length === 0); } module.exports = { command: 'stats <id>', desc: 'Get connection folder statistics', builder: yargs => { yargs.options({ 'connectAs': { desc: 'Account email to impersonate', type: 'string', group: 'Connections' }, 'path': { default: undefined, desc: 'Path to folder, root is default', type: 'string', group: 'Connections' }, 'ignoreShared': { default: true, desc: 'Exclude shared folders', type: 'boolean', group: 'Connections' }, 'ignoreHidden': { default: true, desc: 'Exclude hidden folders', type: 'boolean', group: 'Connections' }, 'csv': { default: undefined, desc: 'Output results as CSV', type: 'boolean', group: 'Connections' } }); }, handler: argv => { command_1.runCommand(argv, (client, output) => __awaiter(void 0, void 0, void 0, function* () { const params = { fields: ['all'] }; if (!isEmpty(argv.connectAs)) { params.headers = { 'X-Connect-As': argv.connectAs }; } if (!isEmpty(argv.path)) { params.path = argv.path; } if (argv.ignoreShared !== undefined) { params.ignoreShared = argv.ignoreShared ? 1 : 0; } if (argv.ignoreHidden !== undefined) { params.ignoreHidden = argv.ignoreHidden ? 1 : 0; } if (argv.csv) { const result = yield client.connectionStats.downloadCsv(argv.id, params); output.writeText(result); } else { const result = yield client.connectionStats.get(argv.id, params); output.writeItem(result, outputFormat); } })); } };