UNPKG

powerbi-cli

Version:

Power BI command line interface for managing Power BI Embedded workspace collections

73 lines 2.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var pkg = require("../package.json"); var _ = require('lodash'); var util = require('util'); var colors = require("colors"); var defaults = { color: 'white' }; var Cli = (function () { function Cli() { } Cli.print = function (message) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } var params = Array.prototype.slice.call(arguments, 1); Cli.write(arguments[0], params, { color: 'cyan' }); }; Cli.success = function (message) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } var params = Array.prototype.slice.call(arguments, 1); Cli.write(arguments[0], params, { color: 'green' }); }; Cli.warn = function (message) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } var params = Array.prototype.slice.call(arguments, 1); Cli.write(arguments[0], params, { color: 'yellow' }); }; Cli.error = function () { var err = arguments[0]; if (typeof err === 'object') { if (err.message) { Cli.error(err.message); } var serviceError = err; if (serviceError.request) { Cli.error('Method: ', serviceError.request['method']); Cli.error('Url: ', serviceError.request['url']); } if (serviceError.statusCode) { Cli.error('Status Code: ', serviceError.statusCode); } if (serviceError.response && serviceError.response.headers) { for (var key in serviceError.response.headers) { Cli.error(key, ': ', serviceError.response.headers[key]); } } return; } var params = Array.prototype.slice.call(arguments, 1); Cli.write(arguments[0], params, { color: 'red' }); }; Cli.write = function (message, args, options) { if (typeof message === 'string') { var allArgs = [message]; args.forEach(function (a) { return allArgs.push(a); }); var finalMessage = util.format.apply(null, allArgs); return console.log('[', colors.yellow('powerbi'), ']', finalMessage[options.color]); } else { throw new Error('no message defined to print!'); } }; return Cli; }()); exports.Cli = Cli; //# sourceMappingURL=cli.js.map