/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ 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 account = cli.category("account");
  var affinityGroup = account.category("affinity-group").description($("Commands to manage your Affinity Groups"));


  affinityGroup.command("list").description($("List affinity groups available for your account")).option("-s, --subscription <id>", $("the subscription id")).execute(function __1(options, _) { var service, affinityGroups, progress; var __frame = { name: "__1", line: 34 }; return __func(_, this, arguments, __1, 1, __frame, function __$__1() {



      service = utils.createManagementClient(profile.current.getSubscription(options.subscription));


      progress = cli.interaction.progress($("Getting affinity groups")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__1() {


            return service.affinityGroups.list(__cb(_, __frame, 7, 48, function ___(__0, __1) { affinityGroups = __1.affinityGroups; _(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() {


          cli.interaction.formatOutput(affinityGroups, function(outputData) {
            if ((outputData.length === 0)) {
              log.info($("No affinity groups defined")); }
             else {
              log.table(outputData, function(row, item) {
                row.cell($("Name"), item.name);
                row.cell($("Label"), item.label);
                row.cell($("Location"), item.location); }); } ; }); _(); }); }); }); });





  affinityGroup.command("create <name>").description($("Create an affinity group")).option("-s, --subscription <id>", $("the subscription id")).option("-l, --location <name>", $("the data center location")).option("-e, --label <label>", $("the affinity group label")).option("-d, --description <description>", $("the affinity group description")).execute(function __2(name, options, _) { var service, affinityGroupOptions, progress; var __frame = { name: "__2", line: 65 }; return __func(_, this, arguments, __2, 2, __frame, function __$__2() {






      service = utils.createManagementClient(profile.current.getSubscription(options.subscription));

      affinityGroupOptions = {
        label: (options.label ? options.label : (options.description ? name : "")),
        description: (((typeof options.description === "string") ? options.description : undefined)),
        location: options.location,
        name: name };


      progress = cli.interaction.progress($("Creating affinity group")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__2() {

            return service.affinityGroups.create(affinityGroupOptions, __cb(_, __frame, 12, 31, function __$__2() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__2() {

              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__2() { _(); }); }); }); });



  affinityGroup.command("show <name>").description($("Show details about an affinity group")).option("-s, --subscription <id>", $("the subscription id")).execute(function __3(name, options, _) { var service, affinityGroup, progress; var __frame = { name: "__3", line: 86 }; return __func(_, this, arguments, __3, 2, __frame, function __$__3() {



      service = utils.createManagementClient(profile.current.getSubscription(options.subscription));


      progress = cli.interaction.progress($("Getting affinity groups")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__3() {


            return service.affinityGroups.get(name, __cb(_, __frame, 7, 47, function ___(__0, __1) { affinityGroup = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__3() {

              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__3() {


          cli.interaction.formatOutput(affinityGroup, function(outputData) {
            Object.keys(outputData).forEach(function(key) {
              if ((key !== "_")) {
                if ((key === "storageServices")) {
                  log.data(util.format($("%s: "), key));
                  outputData[key].forEach(function(item) {
                    Object.keys(item).forEach(function(property) {
                      log.data(util.format($("       %s: %s"), property, item[property])); }); }); }


                 else {
                  log.data(util.format($("%s: %s"), key, outputData[key])); } ; } ; }); }); _(); }); }); }); });






  affinityGroup.command("delete <name>").description($("Delete an affinity group")).option("-q, --quiet", $("quiet mode, do not ask for delete confirmation")).option("-s, --subscription <id>", $("the subscription id")).execute(function __4(name, options, _) { var service, progress; var __frame = { name: "__4", line: 120 }; return __func(_, this, arguments, __4, 2, __frame, function __$__4() {




      service = utils.createManagementClient(profile.current.getSubscription(options.subscription)); return (function __$__4(_) {

        var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return cli.interaction.confirm(util.format($("Delete affinity group %s? [y/n] "), name), __cb(_, __frame, 3, 45, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -119, 18, function ___(__0, __2) { return (function __$__4(__then) { if (__2) { return _(null); } else { __then(); } ; })(function __$__4() {



          progress = cli.interaction.progress($("Deleting affinity group")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__4() {

                return service.affinityGroups.deleteMethod(name, __cb(_, __frame, 9, 31, function __$__4() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__4() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__4() { _(); }); }); }); }, true)); }); });};
