/*** 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,__catch=__rt.__catch,__tryCatch=__rt.__tryCatch; var util = require("util");
















var fs = require("fs");
var progress = require("progress");
var profile = require("../../../util/profile");
var utils = require("../../../util/utils");
var tagUtils = require("../tag/tagUtils");
var $ = utils.getLocaleString;
var dataLakeStoreUtils = require("./datalakestore.utils");

var readStreamToBuffer = function(strm, callback) {
  var bufs = [];
  strm.on("data", function(d) {
    bufs.push(d); });

  strm.on("end", function() {
    callback(null, Buffer.concat(bufs)); });};



exports.init = function(cli) {
  var log = cli.output;
  var withProgress = cli.interaction.withProgress.bind(cli.interaction);





  var dataLakeCommands = cli.category("datalake").description($("Commands to manage your Data Lake objects"));


  var dataLakeStoreCommands = dataLakeCommands.category("store").description($("Commands to manage your Data Lake Storage objects"));


  var dataLakeStoreFileSystem = dataLakeStoreCommands.category("filesystem").description($("Commands to manage your Data Lake Storage FileSystem"));


  dataLakeStoreFileSystem.command("list [accountName] [path] [listSize]").description($("Lists the contents of the specified path (files and folders).")).usage("[options] <accountName> <path>").option("-n --accountName <accountName>", $("the Data Lake Store account name to execute the action on")).option("-p --path <path>", $("the full path to the folder to list (e.g. /someFolder or /someFolder/someNestedFolder)")).option("-l --listSize <listSize>", $("the optional number of entries to list. The default is all entries, which can potentially take some time for large directories.)")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __1(accountName, path, listSize, options, _) { var subscription, client, parameters, fileStatuses; var __frame = { name: "__1", line: 60 }; return __func(_, this, arguments, __1, 4, __frame, function __$__1() {







      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!path) {
        return _(null, cli.missingArgument("path")); } ;


      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeStoreFileSystemManagementClient(subscription);
      parameters = { };
      if (listSize) {
        parameters = {
          listSize: listSize }; } ;



      return client.fileSystem.listFileStatus(accountName, path, parameters, __cb(_, __frame, 18, 43, function ___(__0, __1) { fileStatuses = __1.fileStatuses.fileStatus;
        dataLakeStoreUtils.formatOutputList(cli, log, options, fileStatuses); _(); }, true)); }); });


  dataLakeStoreFileSystem.command("show [accountName] [path]").description($("Gets the specified Data Lake Store file or folder details")).usage("[options] <accountName> <path>").option("-n --accountName <accountName>", $("the Data Lake Store account name to execute the action on")).option("-p --path <path>", $("the full path to the folder or file to get (e.g. /someFolder or /someFolder/someFile.txt)")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __2(accountName, path, options, _) { var subscription, client, fileStatus; var __frame = { name: "__2", line: 88 }; return __func(_, this, arguments, __2, 3, __frame, function __$__2() {






      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!path) {
        return _(null, cli.missingArgument("path")); } ;


      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeStoreFileSystemManagementClient(subscription);

      return client.fileSystem.getFileStatus(accountName, path, __cb(_, __frame, 12, 41, function ___(__0, __1) { fileStatus = __1.fileStatus;
        dataLakeStoreUtils.formatOutput(cli, log, options, fileStatus); _(); }, true)); }); });


  dataLakeStoreFileSystem.command("delete [accountName] [path] [recurse]").description($("deletes the specified Data Lake Store file or folder, with the option for recursive delete (if the folder has contents)")).usage("[options] <accountName> <path>").option("-n --accountName <accountName>", $("the Data Lake Store account name to execute the action on")).option("-p --path <path>", $("the full path to the folder or file to get (e.g. /someFolder or /someFolder/someFile.txt)")).option("-r --recurse", $("optionally indicates that this should be a recursive delete, which will delete a folder and all contents underneath it.")).option("-q --quiet", $("optionally indicates the delete should be immediately performed with no confirmation or prompting. Use carefully.")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __3(accountName, path, recurse, options, _) { var subscription, client, params; var __frame = { name: "__3", line: 112 }; return __func(_, this, arguments, __3, 4, __frame, function __$__3() {








      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!path) {
        return _(null, cli.missingArgument("path")); } ; return (function __$__3(_) {


        var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return cli.interaction.confirm(util.format($("Delete the file or folder at path: %s? [y/n] "), path), __cb(_, __frame, 9, 45, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -111, 17, function ___(__0, __2) { return (function __$__3(__then) { if (__2) { return _(null); } else { __then(); } ; })(function __$__3() {



          subscription = profile.current.getSubscription(options.subscription);
          client = utils.createDataLakeStoreFileSystemManagementClient(subscription);

          params = { };
          if (!recurse) {
            params.recursive = false; }

           else {
            params.recursive = true; } ;


          return client.fileSystem.deleteMethod(accountName, path, params, __cb(_, __frame, 24, 24, function __$__3() {
            log.info($(("Successfully deleted the item at path: " + path))); _(); }, true)); }); }, true)); }); });


  dataLakeStoreFileSystem.command("create [accountName] [path] [value] [folder] [force]").description($("Creates the specified folder or file, with the option to include content in file creation.")).usage("[options] <accountName> <path>").option("-n --accountName <accountName>", $("the Data Lake Store account name to execute the action on")).option("-p --path <path>", $("the full path to the file to add content to (e.g. /someFolder/someFile.txt)")).option("-v --value <value>", $("optional indicates the contents (as a string) to create the file with. NOTE: This parameter cannot be specified with --folder (-d)")).option("-d --folder", $("optionally specify that the item being created is a folder, not a file. If this is not specified, a file will be created. NOTE: This parameter cannot be specified with --encoding (-e) or --value (-v)")).option("-f --force", $("optionally indicates that the file or folder being created can overwrite the file or folder at path if it already exists (default is false). 'true' must be passed in for the overwrite to work")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __4(accountName, path, value, folder, force, options, _) { var subscription, clientOptions, client, result, parameters; var __frame = { name: "__4", line: 149 }; return __func(_, this, arguments, __4, 6, __frame, function __$__4() {









      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!path) {
        return _(null, cli.missingArgument("path")); } ;


      if (((value && folder))) {
        return _(new Error($("--folder cannot be specified with --value"))); } ;


      subscription = profile.current.getSubscription(options.subscription);
      clientOptions = {
        disableLogFilter: true };


      client = utils.createDataLakeStoreFileSystemManagementClient(subscription, clientOptions); return (function __$__4(__then) {

        if (folder) {
          return client.fileSystem.mkdirs(accountName, path, __cb(_, __frame, 21, 39, function ___(__0, __2) { result = __2;
            if ((result.operationResult !== true)) {
              return _(new Error($("Failed to create the desired directory!"))); } ; __then(); }, true)); } else {



          parameters = { };

          if (force) {
            parameters.overwrite = true; }

           else {
            parameters.overwrite = false; } ;


          parameters.permission = null;
          return withProgress(util.format($("Creating file %s"), path), function __1(log, _) { var __frame = { name: "__1", line: 187 }; return __func(_, this, arguments, __1, 1, __frame, function __$__1() {

              if (value) {

                parameters.streamContents = new Buffer(value); } ;


              return client.fileSystem.create(accountName, path, parameters, __cb(_, __frame, 6, 28, function __$__1() { _(); }, true)); }); }, __cb(_, __frame, 37, 8, __then, true)); } ; })(function __$__4() {



        log.info($(("Successfully created the specified item at path:  " + path))); _(); }); }); });


  dataLakeStoreFileSystem.command("import [accountName] [path] [destination] [force]").description($("Uploads the specified the specified file, to the target destination in an Azure Data Lake. NOTE: Only text files are supported by this command at present.")).usage("[options] <accountName> <path> <destination>").option("-n --accountName <accountName>", $("the Data Lake Store account name to execute the action on")).option("-p --path <path>", $("the full local path to the file to import (e.g. /someFolder/someFile.txt or C:somefoldersomeFile.txt)")).option("-d --destination <destination>", $("the full path in the Data Lake Store where the file should be imported to (e.g. /someFolder/someFile.txt")).option("-f --force", $("optionally indicates that the file or folder being created can overwrite the file or folder at path if it already exists (default is false). 'true' must be passed in for the overwrite to work")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __5(accountName, path, destination, force, options, _) { var subscription, clientOptions, client, parameters, fileStats, fileSizeInBytes, maxBytesToRead, fileHandle, maxAttempts, offset, bar, bytesToRead, appendSucceeded, attemptCount, buffer; var __frame = { name: "__5", line: 208 }; return __func(_, this, arguments, __5, 5, __frame, function __$__5() {








      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!path) {
        return _(null, cli.missingArgument("path")); } ;


      if (!destination) {
        return _(null, cli.missingArgument("destination")); } ;


      subscription = profile.current.getSubscription(options.subscription);
      clientOptions = {
        disableLogFilter: true };


      client = utils.createDataLakeStoreFileSystemManagementClient(subscription, clientOptions);

      parameters = { };

      if (force) {
        parameters.overwrite = true; }

       else {
        parameters.overwrite = false; } ;


      parameters.permission = null;

      return fs.stat(path, __cb(_, __frame, 31, 25, function ___(__0, __1) { fileStats = __1;
        if (fileStats.isDirectory()) {
          return _(new Error($("Cannot import directories, please specify a valid file path"))); } ;


        log.info($("Uploading file %s to the Data Lake Store location: %s ..."), path, destination);
        fileSizeInBytes = fileStats.size;
        maxBytesToRead = ((8 * 1024) * 1024);

        return fs.open(path, "r", __cb(_, __frame, 40, 26, function ___(__0, __2) { fileHandle = __2;
          maxAttempts = 4; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__5() {

                offset = 0;
                bar = new progress("  uploading [:bar] :percent :etas", {
                  complete: "=",
                  incomplete: " ",
                  width: 40,
                  total: fileSizeInBytes }); return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$__5() { __more = false;


                    var __5 = (offset < fileSizeInBytes); if (__5) {
                      bytesToRead = maxBytesToRead;
                      if (((offset + maxBytesToRead) > fileSizeInBytes)) {
                        bytesToRead = (fileSizeInBytes - offset); } ;


                      appendSucceeded = false;
                      attemptCount = 0; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$__5() { __more = false;
                          var __6 = (!appendSucceeded && (attemptCount < maxAttempts)); if (__6) {
                            attemptCount++; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__5() {

                                  buffer = new Buffer(bytesToRead);
                                  return fs.read(fileHandle, buffer, 0, bytesToRead, offset, __cb(_, __frame, 63, 17, function __$__5() { return (function __$__5(__then) {

                                      if ((offset === 0)) {
                                        parameters.streamContents = buffer;
                                        return client.fileSystem.create(accountName, destination, parameters, __cb(_, __frame, 67, 34, __then, true)); } else {


                                        return client.fileSystem.append(accountName, destination, buffer, __cb(_, __frame, 70, 34, __then, true)); } ; })(function __$__5() {


                                      appendSucceeded = true;
                                      offset += bytesToRead;
                                      bar.tick(bytesToRead); __then(); }); }, true)); }); })(function ___(err, __result) { __catch(function __$__5() { if (err) {


                                    if ((attemptCount >= maxAttempts)) {
                                      return _(err); } ;




                                    dataLakeStoreUtils.waitForRetry(attemptCount, true); __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__5() { while (__more) { __loop(); }; __more = true; }); }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$__5() { while (__more) { __loop(); }; __more = true; }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$__5() { _(null, null, true); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__5() {





                  fs.close(fileHandle); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__5() {


              log.info($(("Successfully created the specified item at path:  " + destination))); _(); }); }); }, true)); }, true)); }); });


  dataLakeStoreFileSystem.command("concat [accountName] [paths] [destination] [force]").description($("Concatenates the specified list of files into the specified destination file.")).usage("[options] <accountName> <paths> <destination>").option("-n --accountName <accountName>", $("the Data Lake Store account name to execute the action on")).option("-p --paths <paths>", $("a comma seperated list of full paths to concatenate (e.g. '/someFolder/someFile.txt,/somefolder/somefile2.txt,/anotherFolder/newFile.txt')")).option("-d --destination <destination>", $("specify the target file that all of the files in --paths should be concatenated into (e.g /someFolder/targetFile.txt)")).option("-f --force", $("optionally indicates that the file or folder being created can overwrite the file or folder at path if it already exists (default is false). 'true' must be passed in for the overwrite to work")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __6(accountName, paths, destination, force, options, _) { var subscription, client, fileStatus, pathsBuf; var __frame = { name: "__6", line: 312 }; return __func(_, this, arguments, __6, 5, __frame, function __$__6() {








      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!paths) {
        return _(null, cli.missingArgument("paths")); } ;


      if (!destination) {
        return _(null, cli.missingArgument("destination")); } ;


      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeStoreFileSystemManagementClient(subscription); return (function __$__6(__then) {

        if (force) { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__6() {

                return client.fileSystem.getFileStatus(accountName, destination, __cb(_, __frame, 18, 45, function ___(__0, __2) { fileStatus = __2.fileStatus; return (function __$__6(__then) {
                    if ((fileStatus.type.toLowerCase() === "file")) {
                      return client.fileSystem.deleteMethod(accountName, destination, false, __cb(_, __frame, 20, 30, __then, true)); } else {


                      return _(new Error($("Cannot forcibly concatenate files into a path that is an existing directory. Please use the delete command to remove the directory and try again."))); } ; })(__then); }, true)); }); })(function ___(err, __result) { __catch(function __$__6() { if (err) { __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, __then); }); } else { __then(); } ; })(function __$__6() {







        pathsBuf = new Buffer(("sources=" + paths));
        return withProgress(util.format($("Concatenating specified files into target location: %s"), destination), function __1(log, _) { var __frame = { name: "__1", line: 345 }; return __func(_, this, arguments, __1, 1, __frame, function __$__1() {

            return client.fileSystem.msConcat(accountName, destination, pathsBuf, false, __cb(_, __frame, 1, 28, function __$__1() { _(); }, true)); }); }, __cb(_, __frame, 32, 6, function __$__6() {

          log.info($(("Successfully concatenated the file list into the specified item at path:  " + destination))); _(); }, true)); }); }); });


  dataLakeStoreFileSystem.command("move [accountName] [path] [destination] [force]").description($("Moves (renames) the specified file or folder into the specified destination file or folder.")).usage("[options] <accountName> <path> <destination>").option("-n --accountName <accountName>", $("the Data Lake Store account name to execute the action on")).option("-p --path <path>", $("the path to the file or folder to move (e.g. /someFolder or /someFolder/someFile.txt)")).option("-d --destination <destination>", $("specify the target location to move the file or folder to")).option("-f --force", $("optionally indicates that the file or folder being created can overwrite the file or folder at path if it already exists (default is false). 'true' must be passed in for the overwrite to work")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __7(accountName, path, destination, force, options, _) { var subscription, client; var __frame = { name: "__7", line: 359 }; return __func(_, this, arguments, __7, 5, __frame, function __$__7() {








      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!path) {
        return _(null, cli.missingArgument("paths")); } ;


      if (!destination) {
        return _(null, cli.missingArgument("destination")); } ;


      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeStoreFileSystemManagementClient(subscription); return (function __$__7(__then) {

        if (force) { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__7() {

                return client.fileSystem.deleteMethod(accountName, destination, true, __cb(_, __frame, 18, 28, __then, true)); }); })(function ___(err, __result) { __catch(function __$__7() { if (err) { __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, __then); }); } else { __then(); } ; })(function __$__7() {






        return client.fileSystem.rename(accountName, path, destination, __cb(_, __frame, 25, 24, function __$__7() {
          log.info($(("Successfully moved the file or folder to: " + destination))); _(); }, true)); }); }); });


  dataLakeStoreFileSystem.command("addcontent [accountName] [path] [value]").description($("Appends the specified content to the end of the Data Lake Store file path specified.")).usage("[options] <accountName> <path> <value>").option("-n --accountName <accountName>", $("the Data Lake Store account name to execute the action on")).option("-p --path <path>", $("the full path to the file to add content to (e.g. /someFolder/someFile.txt)")).option("-v --value <value>", $("the contents to append to the file")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __8(accountName, path, value, options, _) { var subscription, clientOptions, client; var __frame = { name: "__8", line: 395 }; return __func(_, this, arguments, __8, 4, __frame, function __$__8() {







      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!path) {
        return _(null, cli.missingArgument("path")); } ;


      if (!value) {
        return _(null, cli.missingArgument("value")); } ;


      subscription = profile.current.getSubscription(options.subscription);

      clientOptions = {
        disableLogFilter: true };


      client = utils.createDataLakeStoreFileSystemManagementClient(subscription, clientOptions);
      return withProgress(util.format($("Adding specified content to file %s"), path), function __1(log, _) { var __frame = { name: "__1", line: 416 }; return __func(_, this, arguments, __1, 1, __frame, function __$__1() {

          return client.fileSystem.append(accountName, path, value, __cb(_, __frame, 1, 26, function __$__1() { _(); }, true)); }); }, __cb(_, __frame, 20, 6, function __$__8() {

        log.info($(("Successfully appended content at the specified path:  " + path))); _(); }, true)); }); });


  dataLakeStoreFileSystem.command("export [accountName] [path] [destination] [force]").description($("Downloads the specified file to the target location. NOTE: Only text files are supported by this command at present.")).usage("[options] <accountName> <path> <destination>").option("-n --accountName <accountName>", $("the Data Lake Store account name to execute the action on")).option("-p --path <path>", $("the full path in the Data Lake Store where the file should be imported to (e.g. /someFolder/someFile.txt")).option("-d --destination <destination>", $("the full local path to the file to import (e.g. /someFolder/someFile.txt or C:somefoldersomeFile.txt)")).option("-f --force", $("optionally indicates that the file being created can overwrite the file at path if it already exists (default is false).")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __9(accountName, path, destination, force, options, _) { var subscription, client, maxBytesToRead, fileStatus, fileSizeInBytes, fileHandle, offset, maxAttempts, bar, bytesToRead, parameters, attemptCount, readSucceeded, response, buff; var __frame = { name: "__9", line: 430 }; return __func(_, this, arguments, __9, 5, __frame, function __$__9() {








      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!path) {
        return _(null, cli.missingArgument("path")); } ;


      if (!destination) {
        return _(null, cli.missingArgument("destination")); } ;


      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeStoreFileSystemManagementClient(subscription);
      maxBytesToRead = ((8 * 1024) * 1024);
      return client.fileSystem.getFileStatus(accountName, path, __cb(_, __frame, 16, 41, function ___(__0, __1) { fileStatus = __1.fileStatus;

        log.info($("Downloading file %s to the specified location: %s"), path, destination);

        fileSizeInBytes = fileStatus.length; return (function __$__9(__then) {

          if (force) {
            return fs.open(destination, "w", __cb(_, __frame, 23, 24, function ___(__0, __2) { fileHandle = __2; __then(); }, true)); } else { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__9() {



                  return fs.open(destination, "wx", __cb(_, __frame, 27, 26, function ___(__0, __3) { fileHandle = __3; __then(); }, true)); }); })(function ___(err, __result) { __catch(function __$__9() { if (err) {


                    return _(new Error($(((("The file at path: " + destination) + " already exists. Please use the --force option to overwrite this file. Actual error reported: ") + err)))); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, __then); }); } ; })(function __$__9() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__9() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__9() {



                      offset = 0;
                      maxAttempts = 4;
                      bar = new progress("  downloading [:bar] :percent :etas", {
                        complete: "=",
                        incomplete: " ",
                        width: 40,
                        total: fileSizeInBytes }); return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$__9() { __more = false;

                          var __9 = (offset < fileSizeInBytes); if (__9) {
                            bytesToRead = maxBytesToRead;
                            if (((offset + maxBytesToRead) > fileSizeInBytes)) {
                              bytesToRead = (fileSizeInBytes - offset); } ;


                            parameters = {
                              length: bytesToRead,
                              offset: offset };


                            attemptCount = 0;
                            readSucceeded = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$__9() { __more = false;
                                var __10 = (!readSucceeded && (attemptCount < maxAttempts)); if (__10) { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__9() {

                                        return client.fileSystem.open(accountName, path, parameters, __cb(_, __frame, 57, 47, function ___(__0, __4) { response = __4;
                                          return readStreamToBuffer(response, __cb(_, __frame, 58, 25, function ___(__0, __5) { buff = __5;
                                            return fs.write(fileHandle, buff, 0, bytesToRead, offset, __cb(_, __frame, 59, 17, function __$__9() {
                                              readSucceeded = true;
                                              offset += bytesToRead;
                                              bar.tick(bytesToRead); __then(); }, true)); }, true)); }, true)); }); })(function ___(err, __result) { __catch(function __$__9() { if (err) {


                                          if ((attemptCount >= maxAttempts)) {
                                            return _(err); } ;




                                          dataLakeStoreUtils.waitForRetry(attemptCount, true); __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__9() { while (__more) { __loop(); }; __more = true; }); }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$__9() { while (__more) { __loop(); }; __more = true; }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(__then); }); })(function ___(err, __result) { __catch(function __$__9() { if (err) {





                        log.info(err); __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__9() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__9() {


                  fs.close(fileHandle); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__9() {


              log.info($(((("Successfully downloaded the specified item at path:  " + path) + " to local path: ") + destination))); _(); }); }); }); }, true)); }); });


  dataLakeStoreFileSystem.command("read [accountName] [path] [length] [offset]").description($("Previews the specified Data Lake Store file starting at index 0 (or the specified offset) until the length is reached, displaying the results to the console.")).usage("[options] <accountName> <path> <length>").option("-n --accountName <accountName>", $("the Data Lake Store account name to execute the action on")).option("-p --path <path>", $("the full path to the file to download (e.g. /someFolder/someFile.txt)")).option("-l --length <length>", $("the length, in bytes, to read from the file")).option("-o --offset <offset>", $("the optional offset to begin reading at (default is 0)")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __10(accountName, path, length, offset, options, _) { var parameters, subscription, response, buff; var __frame = { name: "__10", line: 524 }; return __func(_, this, arguments, __10, 5, __frame, function __$__10() {








      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!path) {
        return _(null, cli.missingArgument("path")); } ;


      if (!length) {
        return _(null, cli.missingArgument("length")); } ;


      if ((offset && (parseInt(offset) < 0))) {
        return _(new Error($(("--offset must be greater than or equal to 0. Value passed in: " + offset)))); } ;


      parameters = {
        length: parseInt(length) };


      if (offset) {
        parameters.offset = parseInt(offset); }

       else {
        parameters.offset = 0; } ;


      subscription = profile.current.getSubscription(options.subscription);

      return withProgress(util.format($("Previewing contents of file %s"), path), function __1(log, _) { var client; var __frame = { name: "__1", line: 555 }; return __func(_, this, arguments, __1, 1, __frame, function __$__1() {

          client = utils.createDataLakeStoreFileSystemManagementClient(subscription);
          return client.fileSystem.open(accountName, path, parameters, __cb(_, __frame, 2, 37, function ___(__0, __1) { response = __1; _(); }, true)); }); }, __cb(_, __frame, 30, 6, function __$__10() {


        return readStreamToBuffer(response, __cb(_, __frame, 36, 17, function ___(__0, __2) { buff = __2;
          log.data(buff.toString()); _(); }, true)); }, true)); }); });


  var dataLakeStoreFileSystemPermissions = dataLakeStoreCommands.category("permissions").description($("Commands to manage your Data Lake Storage FileSystem Permissions"));


  dataLakeStoreFileSystemPermissions.command("show [accountName] [path]").description($("Gets the specified Data Lake Store folder ACL")).usage("[options] <accountName> <path>").option("-n --accountName <accountName>", $("the Data Lake Store account name to execute the action on")).option("-p --path <path>", $("the full path to the folder or file to get (e.g. /someFolder or /someFolder/someFile.txt)")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __11(accountName, path, options, _) { var subscription, client, aclStatus; var __frame = { name: "__11", line: 573 }; return __func(_, this, arguments, __11, 3, __frame, function __$__11() {






      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!path) {
        return _(null, cli.missingArgument("path")); } ;


      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeStoreFileSystemManagementClient(subscription);

      return client.fileSystem.getAclStatus(accountName, path, __cb(_, __frame, 12, 40, function ___(__0, __1) { aclStatus = __1.aclStatus;
        dataLakeStoreUtils.formatOutput(cli, log, options, aclStatus); _(); }, true)); }); });





































  var dataLakeStoreFileSystemPermissionsEntries = dataLakeStoreFileSystemPermissions.category("entry").description($("Commands to manage your Data Lake Storage FileSystem granular permissions entries"));


  dataLakeStoreFileSystemPermissionsEntries.command("delete [accountName] [path] [aclEntries]").description($("deletes the specific ACE entry or entries from the path")).usage("[options] <accountName> <path> <aclEntries>").option("-n --accountName <accountName>", $("the Data Lake Store account name to execute the action on")).option("-p --path <path>", $("the full path to the folder to remove ACEs from (e.g. /someFolder)")).option("-a --aclEntries <aclEntries>", $("a comma delimited list of the fully qualified ACE entry or entries to delete in the format [default:]<user>|<group>:<object Id> (e.g 'user:5546499e-795f-4f5f-b411-8179051f8b0a' or 'default:group:5546499e-795f-4f5f-b411-8179051f8b0a')")).option("-q, --quiet", $("quiet mode (do not ask for delete confirmation)")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __12(accountName, path, aclEntries, options, _) { var subscription, client; var __frame = { name: "__12", line: 635 }; return __func(_, this, arguments, __12, 4, __frame, function __$__12() {








      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!path) {
        return _(null, cli.missingArgument("path")); } ;


      if (!aclEntries) {
        return _(null, cli.missingArgument("aclEntries")); } ; return (function __$__12(_) {


        var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return cli.interaction.confirm(util.format($("Delete Data Lake Store ACL entries: %s for account %s at path %s? [y/n] "), aclEntries, accountName, path), __cb(_, __frame, 13, 45, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -634, 17, function ___(__0, __2) { return (function __$__12(__then) { if (__2) { return _(null); } else { __then(); } ; })(function __$__12() {



          subscription = profile.current.getSubscription(options.subscription);
          client = utils.createDataLakeStoreFileSystemManagementClient(subscription);

          return client.fileSystem.removeAclEntries(accountName, path, aclEntries, __cb(_, __frame, 20, 24, function __$__12() {
            log.info($("Successfully removed the specified ACL entries")); _(); }, true)); }); }, true)); }); });


  dataLakeStoreFileSystemPermissionsEntries.command("set [accountName] [path] [aclEntries]").description($("sets the specified Data Lake Store folder ACE entry or entries")).usage("[options] <accountName> <path> <aclEntries>").option("-n --accountName <accountName>", $("the Data Lake Store account name to execute the action on")).option("-p --path <path>", $("the full path to the folder to set ACEs on (e.g. /someFolder)")).option("-a --aclEntries <aclEntries>", $("a comma delimited list of the fully qualified ACE entries to set in the format [default:]<user>|<group>:<object Id>:<permissions> (e.g 'user:5546499e-795f-4f5f-b411-8179051f8b0a:r-x' or 'default:group:5546499e-795f-4f5f-b411-8179051f8b0a:rwx')")).option("-q, --quiet", $("quiet mode (do not ask for overwrite confirmation)")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __13(accountName, path, aclEntries, options, _) { var subscription, client; var __frame = { name: "__13", line: 667 }; return __func(_, this, arguments, __13, 4, __frame, function __$__13() {








      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!path) {
        return _(null, cli.missingArgument("path")); } ;


      if (!aclEntries) {
        return _(null, cli.missingArgument("aclEntries")); } ; return (function __$__13(_) {


        var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return cli.interaction.confirm(util.format($("Potentially overwrite existing Data Lake Store ACL entries: %s for account %s at path %s? [y/n] "), aclEntries, accountName, path), __cb(_, __frame, 13, 45, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -666, 17, function ___(__0, __2) { return (function __$__13(__then) { if (__2) { return _(null); } else { __then(); } ; })(function __$__13() {



          subscription = profile.current.getSubscription(options.subscription);
          client = utils.createDataLakeStoreFileSystemManagementClient(subscription);

          return client.fileSystem.modifyAclEntries(accountName, path, aclEntries, __cb(_, __frame, 20, 24, function __$__13() {
            log.info($("Successfully set the specified ACL entries")); _(); }, true)); }); }, true)); }); });


  dataLakeStoreFileSystemPermissions.command("set [accountName] [path] [aclSpec]").description($("sets the specified Data Lake Store folder ACL (overwriting the previous ACL entries)")).usage("[options] <accountName> <path> <aclSpec>").option("-n --accountName <accountName>", $("the Data Lake Store account name to execute the action on")).option("-p --path <path>", $("the full path to the folder to remove ACLs from (e.g. /someFolder)")).option("-a --aclSpec <aclSpec>", $("a comma delimited list of fully qualified ACL entries to set in the format [default:]<user>|<group>:<object Id>:<permissions> (e.g 'user:5546499e-795f-4f5f-b411-8179051f8b0a:r-x' or 'default:group:5546499e-795f-4f5f-b411-8179051f8b0a:rwx'). This list must also include default entries (no object ID in the middle)")).option("-q, --quiet", $("quiet mode (do not ask for overwrite confirmation)")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __14(accountName, path, aclSpec, options, _) { var subscription, client; var __frame = { name: "__14", line: 699 }; return __func(_, this, arguments, __14, 4, __frame, function __$__14() {








      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!path) {
        return _(null, cli.missingArgument("path")); } ;


      if (!aclSpec) {
        return _(null, cli.missingArgument("aclSpec")); } ; return (function __$__14(_) {


        var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return cli.interaction.confirm(util.format($("Overwrite existing Data Lake Store ACL with the following ACL: %s for account %s at path %s? [y/n] "), aclSpec, accountName, path), __cb(_, __frame, 13, 45, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -698, 17, function ___(__0, __2) { return (function __$__14(__then) { if (__2) { return _(null); } else { __then(); } ; })(function __$__14() {



          subscription = profile.current.getSubscription(options.subscription);
          client = utils.createDataLakeStoreFileSystemManagementClient(subscription);

          return client.fileSystem.setAcl(accountName, path, aclSpec, __cb(_, __frame, 20, 24, function __$__14() {
            log.info($("Successfully set the ACL")); _(); }, true)); }); }, true)); }); });


  var dataLakeStoreAccount = dataLakeStoreCommands.category("account").description($("Commands to manage your Data Lake Storage accounts"));


  dataLakeStoreAccount.command("list [resource-group]").description($("List all Data Lake Store accounts available for your subscription or subscription and resource group")).usage("[options]").option("-g --resource-group <resource-group>", $("the optional resource group to list the accounts in")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __15(resourceGroup, options, _) { var subscription, accounts; var __frame = { name: "__15", line: 731 }; return __func(_, this, arguments, __15, 2, __frame, function __$__15() {





      subscription = profile.current.getSubscription(options.subscription);
      return listAllDataLakeStoreAccounts(subscription, resourceGroup, __cb(_, __frame, 2, 21, function ___(__0, __1) { accounts = __1;
        dataLakeStoreUtils.formatOutputList(cli, log, options, accounts); _(); }, true)); }); });


  dataLakeStoreAccount.command("show [accountName] [resource-group]").description($("Shows a Data Lake Store Account based on account name")).usage("[options] <accountName>").option("-n --accountName <accountName>", $("the Data Lake Store account name")).option("-g --resource-group <resource-group>", $("the optional resource group to list the accounts in")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __16(accountName, resourceGroup, options, _) { var subscription, client, dataLakeStoreAccount; var __frame = { name: "__16", line: 743 }; return __func(_, this, arguments, __16, 3, __frame, function __$__16() {






      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeStoreManagementClient(subscription); return (function __$__16(__then) {

        if (!resourceGroup) {
          return getResrouceGroupByAccountName(subscription, resourceGroup, accountName, __cb(_, __frame, 9, 24, function ___(__0, __1) { resourceGroup = __1; __then(); }, true)); } else { __then(); } ; })(function __$__16() {


        return client.account.get(resourceGroup, accountName, __cb(_, __frame, 12, 48, function ___(__0, __2) { dataLakeStoreAccount = __2;

          dataLakeStoreUtils.formatOutput(cli, log, options, dataLakeStoreAccount); _(); }, true)); }); }); });


  dataLakeStoreAccount.command("delete [accountName] [resource-group]").description($("Deletes a Data Lake Store Account based on account name")).usage("[options] <accountName>").option("-n --accountName <accountName>", $("the Data Lake Store account name")).option("-g --resource-group <resource-group>", $("the optional resource group to force the command to find the Data Lake Store account to delete in.")).option("-q, --quiet", $("quiet mode (do not ask for delete confirmation)")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __17(accountName, resourceGroup, options, _) { var subscription, client; var __frame = { name: "__17", line: 767 }; return __func(_, this, arguments, __17, 3, __frame, function __$__17() {







      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ; return (function __$__17(_) {


        var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return cli.interaction.confirm(util.format($("Delete Data Lake Store Account %s? [y/n] "), accountName), __cb(_, __frame, 5, 45, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -766, 17, function ___(__0, __2) { return (function __$__17(__then) { if (__2) { return _(null); } else { __then(); } ; })(function __$__17() {



          subscription = profile.current.getSubscription(options.subscription);
          client = utils.createDataLakeStoreManagementClient(subscription); return (function __$__17(__then) {

            if (!resourceGroup) {
              return getResrouceGroupByAccountName(subscription, resourceGroup, accountName, __cb(_, __frame, 13, 24, function ___(__0, __3) { resourceGroup = __3; __then(); }, true)); } else { __then(); } ; })(function __$__17() {


            return client.account.deleteMethod(resourceGroup, accountName, __cb(_, __frame, 16, 21, function __$__17() {

              log.info($("Successfully deleted the specified Data Lake Store account.")); _(); }, true)); }); }); }, true)); }); });


  dataLakeStoreAccount.command("create [accountName] [location] [resource-group] [defaultGroup]").description($("Creates a Data Lake Store Account")).usage("[options] <accountName> <location> <resource-group>").option("-n --accountName <accountName>", $("The Data Lake Store account name to create")).option("-l --location <location>", $("the location the Data Lake Store account will be created in. Valid values are: North Central US, South Central US, Central US, West Europe, North Europe, West US, East US, East US 2, Japan East, Japan West, Brazil South, Southeast Asia, East Asia, Australia East, Australia Southeast")).option("-g --resource-group <resource-group>", $("the resource group to create the account in")).option("-d --defaultGroup <defaultGroup>", $("the optional default permissions group to add to the account when created")).option("-t --tags <tags>", $(("Tags to set to the the Data Lake Store account. Can be mutliple. " + "In the format of 'name=value'. Name is required and value is optional. For example, -t tag1=value1;tag2"))).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __18(accountName, location, resourceGroup, defaultGroup, options, _) { var subscription, tags, dataLakeStoreAccount; var __frame = { name: "__18", line: 798 }; return __func(_, this, arguments, __18, 5, __frame, function __$__18() {










      subscription = profile.current.getSubscription(options.subscription);
      tags = { };
      tags = tagUtils.buildTagsParameter(tags, options);
      return createOrUpdateDataLakeStoreAccount(subscription, accountName, resourceGroup, location, defaultGroup, tags, __cb(_, __frame, 4, 33, function ___(__0, __1) { dataLakeStoreAccount = __1;
        dataLakeStoreUtils.formatOutput(cli, log, options, dataLakeStoreAccount); _(); }, true)); }); });


  dataLakeStoreAccount.command("set [accountName] [resource-group] [defaultGroup]").description($("Updates the properties of an existing Data Lake Store Account")).usage("[options] <accountName>").option("-n --accountName <accountName>", $("The Data Lake Store account name to update with new tags and/or default permissions group")).option("-g --resource-group <resource-group>", $("the optional resource group to forcibly look for the account to update in")).option("-d --defaultGroup <defaultGroup>", $("the optional default permissions group to set in the existing account")).option("-t --tags <tags>", $(("Tags to set to the Data Lake Store account. Can be mutliple. " + "In the format of 'name=value'. Name is required and value is optional. For example, -t tag1=value1;tag2"))).option("--no-tags", $("remove all existing tags")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __19(accountName, resourceGroup, defaultGroup, options, _) { var subscription, client, dataLakeStoreAccount, tags; var __frame = { name: "__19", line: 816 }; return __func(_, this, arguments, __19, 4, __frame, function __$__19() {










      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeStoreManagementClient(subscription); return (function __$__19(__then) {

        if (!resourceGroup) {
          return getResrouceGroupByAccountName(subscription, resourceGroup, accountName, __cb(_, __frame, 5, 24, function ___(__0, __1) { resourceGroup = __1; __then(); }, true)); } else { __then(); } ; })(function __$__19() {


        return client.account.get(resourceGroup, accountName, __cb(_, __frame, 8, 48, function ___(__0, __2) { dataLakeStoreAccount = __2;

          if (!defaultGroup) {
            defaultGroup = dataLakeStoreAccount.properties.defaultGroup; } ;


          tags = { };
          if ((!options.tags && (!options.no - tags))) {
            tags = dataLakeStoreAccount.tags; }

           else {
            tags = tagUtils.buildTagsParameter(tags, options); } ;


          return createOrUpdateDataLakeStoreAccount(subscription, accountName, resourceGroup, dataLakeStoreAccount.location, defaultGroup, tags, __cb(_, __frame, 22, 30, function ___(__0, __3) { dataLakeStoreAccount = __3;
            dataLakeStoreUtils.formatOutput(cli, log, options, dataLakeStoreAccount); _(); }, true)); }, true)); }); }); });


  function createOrUpdateDataLakeStoreAccount(subscription, accountName, resourceGroup, location, defaultGroup, tags, _) { var client, create, accountParams; var __frame = { name: "createOrUpdateDataLakeStoreAccount", line: 842 }; return __func(_, this, arguments, createOrUpdateDataLakeStoreAccount, 6, __frame, function __$createOrUpdateDataLakeStoreAccount() {
      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;

      if (!location) {
        return _(null, cli.missingArgument("location")); } ;

      if (!resourceGroup) {
        return _(null, cli.missingArgument("resourceGroup")); } ;


      client = utils.createDataLakeStoreManagementClient(subscription);
      create = false; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$createOrUpdateDataLakeStoreAccount() {

            return client.account.get(resourceGroup, accountName, __cb(_, __frame, 14, 23, __then, true)); }); })(function ___(err, __result) { __catch(function __$createOrUpdateDataLakeStoreAccount() { if (err) {


              create = true; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$createOrUpdateDataLakeStoreAccount() {


          accountParams = {
            name: accountName,
            location: location,
            properties: {
              defaultGroup: defaultGroup },

            tags: tags }; return (function __$createOrUpdateDataLakeStoreAccount(__then) {


            if (create) {
              return client.account.create(resourceGroup, accountParams.name, accountParams, __cb(_, __frame, 30, 23, __then, true)); } else {


              return client.account.update(resourceGroup, accountParams.name, accountParams, __cb(_, __frame, 33, 23, __then, true)); } ; })(function __$createOrUpdateDataLakeStoreAccount() {


            return client.account.get(resourceGroup, accountName, __cb(_, __frame, 36, 28, _, true)); }); }); }); }); };


  function listAllDataLakeStoreAccounts(subscription, resourceGroup, _) { var client, response, accounts; var __frame = { name: "listAllDataLakeStoreAccounts", line: 881 }; return __func(_, this, arguments, listAllDataLakeStoreAccounts, 2, __frame, function __$listAllDataLakeStoreAccounts() {
      client = utils.createDataLakeStoreManagementClient(subscription); return (function __$listAllDataLakeStoreAccounts(__then) {


        if (!resourceGroup) {
          return client.account.list(resourceGroup, __cb(_, __frame, 5, 32, function ___(__0, __1) { response = __1;
            accounts = response;
            while (response.nextLink) {
              response = client.account.listNext(response.nextLink);
              accounts.push.apply(accounts, response); }; __then(); }, true)); } else {



          return client.account.listByResourceGroup(resourceGroup, __cb(_, __frame, 13, 32, function ___(__0, __2) { response = __2;
            accounts = response;
            while (response.nextLink) {
              response = client.account.listByResourceGroupNext(response.nextLink);
              accounts.push.apply(accounts, response); }; __then(); }, true)); } ; })(function __$listAllDataLakeStoreAccounts() {



        return _(null, accounts); }); }); };


  function getResrouceGroupByAccountName(subscription, resourceGroup, name, _) { var accounts, i, acctId, rgStart, rgEnd; var __frame = { name: "getResrouceGroupByAccountName", line: 905 }; return __func(_, this, arguments, getResrouceGroupByAccountName, 3, __frame, function __$getResrouceGroupByAccountName() {
      return listAllDataLakeStoreAccounts(subscription, resourceGroup, __cb(_, __frame, 1, 19, function ___(__0, __1) { accounts = __1;
        for (i = 0; (i < accounts.length); i++) {
          if ((accounts[i].name === name)) {
            acctId = accounts[i].id;
            rgStart = (acctId.indexOf("resourceGroups/") + ("resourceGroups/".length));
            rgEnd = acctId.indexOf("/providers/");
            return _(null, acctId.substring(rgStart, rgEnd)); } ; };



        return _(new Error($(((((("Could not find account: " + name) + " in any resource group in subscription: ") + subscription.name) + " with id: ") + subscription.id)))); }, true)); }); };};
