cloudcms-cli
Version:
Cloud CMS Command-Line client
119 lines (96 loc) • 2.86 kB
JavaScript
var path = require("path");
var pkg = require("../../package.json");
var helper = require("../../lib/helper");
module.exports = function(groups, commands)
{
var buffer = "";
var countKeys = function(obj)
{
return Object.keys(obj).length;
};
var append = function(text)
{
if (text) {
buffer += text;
}
buffer += "\r\n";
};
var appendCommand = function(group, command)
{
var schema = command.schema();
append("### " + command.name);
append(command.description);
append();
if (schema && schema.properties && schema.properties.length > 0) {
append("#### Usage");
append();
append("|Name|Required|Type|Switches|Description|");
append("|----|--------|----|---------|-----------|");
for (var i = 0; i < schema.properties.length; i++)
{
var prop = schema.properties[i];
var propertyName = prop.name;
var description = prop.helper;
if (!description) {
description = prop.description;
}
var required = (prop.required ? "required": "");
var type = prop.type;
var args = "";
for (var z = 0; z < prop.args.length; z++)
{
if (z > 0) {
args += ", ";
}
args += "--" + prop.args[z];
}
append("|" + propertyName + "|" + required + "|" + type + "|" + args + "|" + description + "|");
}
}
append();
append("#### Example");
append();
var code = "cloudcms";
if (group) {
code += " " + group.name;
}
code += " " + command.name;
if (schema)
{
code += " " + helper.generateSchemaSummary(schema);
}
append("````");
append(code);
append("````");
append();
};
append("# Cloud CMS Command Line");
append();
append("## Root Commands");
append();
// add in commands that don't have a group
for (var j = 0; j < commands.length; j++)
{
var command = commands[j];
if (!command.group)
{
appendCommand(null, command);
}
}
for (var i = 0; i < groups.length; i++)
{
var group = groups[i];
append("## " + group.name);
append(group.description);
append();
for (var j = 0; j < commands.length; j++)
{
var command = commands[j];
if (command.group === group.name)
{
appendCommand(group, command);
}
}
}
return buffer;
};