rainbow-cli
Version:
Rainbow CLI application based on the Rainbow SDK for Node.js
246 lines (219 loc) • 11.7 kB
JavaScript
;
let CInternal = require("../commands/CInternal");
const Logger = require("../common/Logger");
const Middleware = require("../common/Middleware");
const Message = require("../common/Message");
class Internal {
constructor(program, prefs) {
this._program = program;
this._prefs = prefs;
this._internal = new CInternal(this._prefs);
}
start() {
this.listOfCommands();
}
stop() { }
listOfCommands() {
var that = this;
this._program
.command("dashboard payasyougo")
.description("Display pay-as-you-go applications metrics for current month")
.option("-m, --month <month>", "Get metrics for a specific month. Format is YYYYMM")
.option("-s, --since <month>", "Get metrics since a specific month. Format is YYYYMM")
.option("-u, --until <month>", "Get metrics until a specific month. Format is YYYYMM. Requires -s/--since parameter")
.option("-f, --file <filename>", "Print result to a file in CSV")
.option("-o, --owner <ownerid>", "Filter by owner of applications")
.option("-e, --external", "Filter by external application owners")
.option("-i, --internal", "Filter by internal application owners")
.option("-a, --active", "Filter by active applications (API consumption not null)")
.option("-v, --verbose", "Use verbose console mode")
.option("--json", "Write the JSON result to standard stdout")
.action(function (commands) {
Middleware.parseCommand(commands)
.then(() => {
if (commands.month && (commands.since || commands.until)) {
throw { error: { errorDetails: "-m/--month and -s/--since or -u/--until are exclusive." } };
}
if (commands.until && !commands.since) {
throw { error: { errorDetails: "-u/--until requires -s/--since." } };
}
if (commands.external && commands.internal) {
throw { error: { errorDetails: "-e/--external and -i/--internal are exclusive."} };
}
var intOrExt = "both";
if (commands.internal) {
intOrExt = "internal";
}
if (commands.external) {
intOrExt = "external"
}
Logger.isActive = commands.verbose || false;
var options = {
month: commands.month,
since: commands.since,
until: commands.until,
group: true,
csv: commands.file,
owner: commands.owner,
intOrExt: intOrExt,
active: commands.active,
kpi: "payasyougo"
};
that._internal.dashboardApplications(options);
})
.catch(err => {
Message.error(err, {});
});
});
this._program
.command("dashboard business")
.description("Display business applications metrics for current month")
.option("-m, --month <month>", "Get metrics for a specific month. Format is YYYYMM")
.option("-s, --since <month>", "Get metrics since a specific month. Format is YYYYMM")
.option("-u, --until <month>", "Get metrics until a specific month. Format is YYYYMM. Requires -s/--since parameter")
.option("-f, --file <filename>", "Print result to a file in CSV")
.option("-o, --owner <ownerid>", "Filter by owner of applications")
.option("-e, --external", "Filter by external application owners")
.option("-i, --internal", "Filter by internal application owners")
.option("-r, --reason <reason>", "Filter by deployment reason. More than one reason can be specified and separated by commas.")
.option("-a, --active", "Filter by active applications (API consumption not null)")
.option("-v, --verbose", "Use verbose console mode")
.option("--json", "Write the JSON result to standard stdout")
.action(function (commands) {
Middleware.parseCommand(commands)
.then(() => {
if (commands.month && (commands.since || commands.until)) {
throw { error: { errorDetails: "-m/--month and -s/--since or -u/--until are exclusive." } };
}
if (commands.until && !commands.since) {
throw { error: { errorDetails: "-u/--until requires -s/--since." } };
}
if (commands.external && commands.internal) {
throw { error: { errorDetails: "-e/--external and -i/--internal are exclusive."} };
}
var intOrExt = "both";
if (commands.internal) {
intOrExt = "internal";
}
if (commands.external) {
intOrExt = "external"
}
Logger.isActive = commands.verbose || false;
var options = {
month: commands.month,
since: commands.since,
until: commands.until,
group: true,
csv: commands.file,
owner: commands.owner,
intOrExt: intOrExt,
active: commands.active,
reason: commands.reason,
kpi: "business"
};
that._internal.dashboardApplications(options);
})
.catch(err => {
Message.error(err, {});
});
});
this._program
.command("dashboard internal")
.description("Display internal applications metrics for current month")
.option("-m, --month <month>", "Get metrics for a specific month. Format is YYYYMM")
.option("-s, --since <month>", "Get metrics since a specific month. Format is YYYYMM")
.option("-u, --until <month>", "Get metrics until a specific month. Format is YYYYMM. Requires -s/--since parameter")
.option("-f, --file <filename>", "Print result to a file in CSV")
.option("-o, --owner <ownerid>", "Filter by owner of applications")
.option("-e, --external", "Filter by external application owners")
.option("-i, --internal", "Filter by internal application owners")
.option("-a, --active", "Filter by active applications (API consumption not null)")
.option("-v, --verbose", "Use verbose console mode")
.option("--json", "Write the JSON result to standard stdout")
.action(function (commands) {
Middleware.parseCommand(commands)
.then(() => {
if (commands.month && (commands.since || commands.until)) {
throw { error: { errorDetails: "-m/--month and -s/--since or -u/--until are exclusive." } };
}
if (commands.until && !commands.since) {
throw { error: { errorDetails: "-u/--until requires -s/--since." } };
}
if (commands.external && commands.internal) {
throw { error: { errorDetails: "-e/--external and -i/--internal are exclusive."} };
}
var intOrExt = "both";
if (commands.internal) {
intOrExt = "internal";
}
if (commands.external) {
intOrExt = "external"
}
Logger.isActive = commands.verbose || false;
var options = {
month: commands.month,
since: commands.since,
until: commands.until,
group: true,
csv: commands.file,
owner: commands.owner,
intOrExt: intOrExt,
active: commands.active,
kpi: "internal"
};
that._internal.dashboardApplications(options);
})
.catch(err => {
Message.error(err, {});
});
});
this._program
.command("dashboard indeployment")
.description("Display indeployment applications")
.option("-f, --file <filename>", "Print result to a file in CSV")
.option("-v, --verbose", "Use verbose console mode")
.option("--json", "Write the JSON result to standard stdout")
.action(function (commands) {
Middleware.parseCommand(commands)
.then(() => {
Logger.isActive = commands.verbose || false;
var options = {
noOutput: commands.json || false,
csv: commands.file
};
that._internal.dashboardInDeployment(options);
})
.catch(err => {
Message.error(err, {});
});
});
this._program
.command("dashboard developers")
.description("Display developers metrics for current month")
.option("-m, --month <month>", "Get metrics for a specific month. Format is YYYYMM")
.option("-f, --file <filename>", "Print result to a file in CSV")
.option("-s, --sandbox", "Get developers sandbox metrics instead")
.option("-p, --pay", "Get developers pay as you go metrics instead")
.option("-v, --verbose", "Use verbose console mode")
.option("--json", "Write the JSON result to standard stdout")
.action(function (commands) {
Middleware.parseCommand(commands)
.then(() => {
Logger.isActive = commands.verbose || false;
var options = {
noOutput: commands.json || false,
month: commands.month,
csv: commands.file || "",
sandbox: commands.sandbox || false,
pay: commands.pay || false,
format: "full"
};
that._internal.dashboardDevelopers(options);
})
.catch(err => {
Message.error(err, {});
});
});
}
}
module.exports = Internal;