cloudcms-cli
Version:
Cloud CMS Command-Line client
102 lines (91 loc) • 3.62 kB
JavaScript
var helper = require("../../../helper");
var AbstractCommand = require("../../abstract");
class RepairBranchCommand extends AbstractCommand
{
constructor()
{
super({
"group": "admin",
"name": "repair-branch",
"description": "Runs repair operations over a branch to ensure any inconsistencies are detected or automatically fixed",
"schema": {
"properties": [{
"name": "repositoryId",
"type": "string",
"description": "Enter the repository ID",
"required": true,
"args": ["repository", "r"]
}, {
"name": "branchId",
"type": "string",
"description": "Enter the branch ID",
"required": true,
"args": ["branch", "b"]
}, {
"name": "operation",
"type": "string",
"description": "Allows for optional specification of which operations to perform (tips, danglingAssociations, incorrectChangesets, relators, badChildAssociationQNames, incorrectQNames, incorrectAttachments)",
"required": false,
"args": ["operation", "op"]
}, {
"name": "commit",
"type": "boolean",
"description": "Automatically commits repairs for any issues found with the branch",
"required": false,
"args": ["commit"]
}, {
"name": "typeQNames",
"type": "string",
"description": "(Only for relators operation) Type QNames to repair instances of",
"required": false,
"args": ["typeQName", "type"]
}, {
"name": "username",
"type": "string",
"description": "Admin username",
"required": true,
"args": ["username", "u"]
}, {
"name": "password",
"type": "string",
"description": "Admin password",
"required": true,
"hidden": true,
"args": ["password", "p"]
}]
}
});
}
// NOTE: Username and password are not being used, can we remove them?
handle(options, callback)
{
var operations = null;
if (typeof(options.operation) === "string") {
options.operation = [options.operation];
}
// process array
if (options.operation)
{
operations = {};
for (var i = 0; i < options.operation.length; i++)
{
operations[options.operation[i]] = true;
}
}
var config = {};
if (options.typeQNames)
{
var typeQNames = options.typeQNames;
if (typeof(typeQNames) === "string") {
typeQNames = [typeQNames];
}
config.typeQNames = typeQNames;
}
// call workhorse function
helper.repairBranch(options.repositoryId, options.branchId, operations, (options.commit ? true : false), options.username, options.password, config, function(err) {
console.log(""); // this forces stdout to flush
callback(err);
});
}
}
module.exports = RepairBranchCommand;