skysync-cli
Version:
SkySync Command Line Interface
306 lines (305 loc) • 8.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.securityMappingOutputFormat = exports.itemOutputFormat = exports.statTransform = exports.statsOutputFormat = exports.searchCriteriaIsMissing = exports.getSearchArgs = exports.auditOutputFormat = exports.historyOutputFormat = exports.detailOutputFormat = exports.listOutputFormat = exports.jobsSearchArgumentsDefault = void 0;
const util_1 = require("../util");
const sdk_1 = require("../../sdk");
exports.jobsSearchArgumentsDefault = Object.assign({ 'kind': {
desc: 'Job Kind',
type: 'string',
group: 'Search'
}, 'active': {
desc: 'Only retrieve active jobs',
type: 'boolean',
group: 'Search',
default: undefined
}, 'parent': {
desc: 'Search by the parent job ID',
type: 'string',
group: 'Search'
}, 'node': {
desc: 'Search by the currently executing node address',
type: 'string',
group: 'Search'
}, 'status': {
desc: 'Search by the current job status (idle, start, running, paused)',
type: 'string',
group: 'Search'
} }, util_1.listArgumentsDefault);
exports.listOutputFormat = {
table: [
{
header: 'ID',
property: 'id'
},
{
header: 'Name',
property: 'name'
},
{
header: 'Discriminator',
property: 'discriminator'
},
{
header: 'Kind',
property: 'kind'
},
{
header: 'Enabled',
property: 'disabled',
transform: val => !val
},
{
header: 'Status',
property: 'status'
}
],
json: [
'schedule'
]
};
exports.detailOutputFormat = {
table: [
{
header: 'ID',
property: 'id'
},
{
header: 'Name',
property: 'name'
},
{
header: 'Kind',
property: 'kind'
},
{
header: 'Enabled',
property: 'disabled',
transform: val => !val
},
{
header: 'Status',
property: 'status'
}
],
json: [
'schedule',
'transfer',
]
};
exports.historyOutputFormat = {
table: [
{
header: 'ID',
property: 'id'
},
{
header: 'JobID',
property: 'job_id'
},
{
header: 'Progress',
property: 'progress',
transform: sdk_1.DataFormatter.formatPercent
},
{
header: 'Start',
property: 'start_time',
transform: sdk_1.DataFormatter.formatDate
},
{
header: 'End',
property: 'end_time',
transform: sdk_1.DataFormatter.formatDate
},
{
header: 'Status',
property: 'status'
},
{
header: 'Node',
property: 'node_address'
}
],
json: [
'phase',
'stats',
'duration'
]
};
exports.auditOutputFormat = {
table: [
{
header: 'Level',
property: 'level'
},
{
header: 'Event',
property: 'event'
},
{
header: 'RecordedOn',
property: 'recorded_on',
transform: val => sdk_1.DataFormatter.formatDate(val)
},
{
header: 'Reason',
property: 'reason'
}
],
json: [
'execution_id',
'target'
]
};
function getSearchArgs(argv) {
if (argv.all !== undefined) {
return {};
}
return {
kind: argv.kind,
q: argv.search,
node: argv.node,
active: argv.active,
parent: argv.parent,
offset: argv.offset,
status: argv.status,
limit: argv.limit
};
}
exports.getSearchArgs = getSearchArgs;
function searchCriteriaIsMissing(argv) {
return argv.all === undefined
&& argv.parent === undefined
&& argv.kind === undefined
&& argv.q === undefined
&& argv.status === undefined
&& argv.active === undefined;
}
exports.searchCriteriaIsMissing = searchCriteriaIsMissing;
exports.statsOutputFormat = {
table: [
{
header: 'Timestamp',
property: 'timestamp',
transform: val => sdk_1.DataFormatter.formatDate(val, { displayTime: false })
},
{
header: 'Content',
property: 'stats',
transform: statTransform('bytes', sdk_1.DataFormatter.formatBytes)
},
{
header: 'Files',
property: 'stats',
transform: statTransform('files')
},
{
header: 'Folders',
property: 'stats',
transform: statTransform('folders')
}
]
};
function statTransform(statKey, format) {
if (!format) {
format = sdk_1.DataFormatter.formatNumber;
}
return val => {
let source = 0, destination = 0;
Object.keys(val).forEach(key => {
const stat = val[key];
if (stat.source && statKey in stat.source) {
source += (stat.source[statKey] || 0);
}
if (stat.destination && statKey in stat.destination) {
destination += (stat.destination[statKey] || 0);
}
});
return `(${format(source)} ${'\u2191'.gray} ${format(destination)} ${'\u2193'.gray})`;
};
}
exports.statTransform = statTransform;
const maxPathLength = 50;
function truncatePath(path) {
const len = path && path.length;
if (len > maxPathLength) {
path = '…' + path.substring(len - maxPathLength, len);
}
return path;
}
exports.itemOutputFormat = {
table: [
{
header: 'ID',
property: 'id'
},
{
header: 'Source',
property: 'source.path',
transform: truncatePath
},
{
header: ' ',
property: 'source_to_destination',
transform: val => {
return val ? '\u2192' : '\u2190';
}
},
{
header: 'Destination',
property: 'destination.path',
transform: truncatePath
},
{
header: 'Size',
property: null,
transform: val => {
if (!val) {
return '';
}
const size = Boolean(val.source_to_destination && val.destination && val.destination.bytes)
? (val.destination && val.destination.bytes)
: (val.source && val.source.bytes);
if (!size) {
return '';
}
return size && sdk_1.DataFormatter.formatBytes(size);
}
},
{
header: 'Status',
property: 'status'
}
],
json: [
'source',
'destination',
'audit_category',
'retried',
'processing',
'transferred_on'
]
};
exports.securityMappingOutputFormat = {
table: [
{
header: 'Source',
property: 'source',
transform: val => val && (val.name || val.email || val.username || val.id)
},
{
header: 'Destination',
property: 'destination',
transform: val => val && (val.name || val.email || val.username || val.id)
},
{
header: 'Resolution',
property: 'resolution'
},
{
header: 'Message',
property: 'message'
}
],
json: ['id', 'source', 'destination']
};