UNPKG

azure-cli

Version:

Microsoft Azure Cross Platform Command Line tool

103 lines (31 loc) 6 kB
/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ "use strict"; var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb,__tryCatch=__rt.__tryCatch; var util = require("util"); var profile = require("../../../util/profile"); var utils = require("../../../util/utils"); var $ = utils.getLocaleString; exports.init = function(cli) { var log = cli.output; var usage = cli.category("usage").description($("Command to view your aggregated Azure usage data")); usage.command("list [reportedStartTime] [reportedEndTime]").description($("List the usage aggregates for a provided time range. When --json flag is used, it will get the information from all the pages and then provide the final json array.")).option("--reportedStartTime <datetime>", $("The start of the time range to retrieve data for, in 'yyyy-mm-dd' format.")).option("--reportedEndTime <datetime>", $("The end of the time range to retrieve data for, in 'yyyy-mm-dd' format.")).option("--granularity <daily/hourly>", $("Value is either daily (default) or hourly to tell the API how to return the results grouped by day or hour.")).option("--showDetails", $("When this boolean flag is provided, the aggregates are broken down into the instance metadata which is more granular.")).option("--continuationToken <url>", $("Retrieved from previous calls, this is the bookmark used for progress when the responses are paged.")).option("--subscription <subscription>", $("the subscription identifier")).option("| more", $("Provides paging support. Press 'Enter' for more information.")).execute(function __1(reportedStartTime, reportedEndTime, options, _) { var subscription, client, usageOptions, progress, result, usages; function displayUsages(usages, interaction, log) { interaction.formatOutput(usages, function(data) { if ((data && (data.length > 0))) { log.table(data, function(row, item) { row.cell($("Usage Start "), item.usageStartTime); row.cell($("Usage End "), item.usageEndTime); row.cell($("Meter Category "), item.meterCategory); row.cell($("Meter Name "), item.meterName); row.cell($("Quantity "), ((item.quantity + " ") + item.unit)); }); } else { log.info($("No usage aggregates found for that time period.")); } ; }); }; var __frame = { name: "__1", line: 40 }; return __func(_, this, arguments, __1, 3, __frame, function __$__1() { subscription = profile.current.getSubscription(options.subscription); client = utils.createUsageManagementClient(subscription); return (function __$__1(__then) { if (!reportedStartTime) { return cli.interaction.promptIfNotGiven($("reportedStartTime: "), reportedStartTime, __cb(_, __frame, 4, 42, function ___(__0, __1) { reportedStartTime = __1; __then(); }, true)); } else { __then(); } ; })(function __$__1() { return (function __$__1(__then) { if (!reportedEndTime) { return cli.interaction.promptIfNotGiven($("reportedEndTime: "), reportedEndTime, __cb(_, __frame, 7, 40, function ___(__0, __2) { reportedEndTime = __2; __then(); }, true)); } else { __then(); } ; })(function __$__1() { usageOptions = { }; usageOptions.showDetails = options.showDetails; if (options.granularity) { if ((options.granularity.toLowerCase() === "daily")) { usageOptions.aggregationGranularity = "Daily"; } else { if ((options.granularity.toLowerCase() === "hourly")) { usageOptions.aggregationGranularity = "Hourly"; } else { return _(new Error(util.format("The value \"%s\" provided for granularity is invalid. Valid values are: \"daily, hourly\".", options.granularity))); } ; } ; } else { usageOptions.aggregationGranularity = "Daily"; } ; if (options.continuationToken) { usageOptions.continuationToken = options.continuationToken; } ; progress = cli.interaction.progress($("Listing usage aggregates")); usages = []; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__1() { return client.usageAggregates.list(reportedStartTime, reportedEndTime, usageOptions, __cb(_, __frame, 46, 38, function ___(__0, __3) { result = __3; usages = usages.concat(result); return (function __$__1(__then) { if (options.json) { return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$__1() { __more = false; var __9 = result.nextLink; if (__9) { return client.usageAggregates.listNext(result.nextLink, __cb(_, __frame, 50, 42, function ___(__0, __4) { result = __4; usages = usages.concat(result); while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$__1() { displayUsages(usages, cli.interaction, log); __then(); }); } else { displayUsages(result, cli.interaction, log); return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$__1() { __more = false; var __11 = result.nextLink; if (__11) { return client.usageAggregates.listNext(result.nextLink, __cb(_, __frame, 57, 42, function ___(__0, __5) { result = __5; displayUsages(result, cli.interaction, log); while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(__then); } ; })(function __$__1() { _(null, null, true); }); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__1() { progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__1() { _(); }); }); }); }); }); });};