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AAK,WAAW,GAAK,WAAW,EAClC,IACA,SAAU,GACR,EAAS,EACX,GAEJ,EAQA,WAAW,UAAU,kBAAoB,SAAU,EAAU,GAC3D,IAAI,EAAO,KACP,EAAO,QAAQ,QACf,EAAM,QAAQ,GAGd,EAAY,IADA,QAAQ,sBACR,CAAc,GAE9B,EAAI,SAAS,GAAW,SAAU,GAC3B,IACH,EAAK,WAAW,EAAK,QAAQ,IAAa,EACtC,EAAK,cACP,EAAK,aAAa,UAIlB,GACF,EAAS,EAEb,GACF,EAQA,WAAW,UAAU,MAAQ,SAAU,EAAS,GAC9C,IAAI,EAAO,KACX,EAAK,QAAU,EAKf,IAAI,GAAa,EACb,EAAc,QAAQ,KAC1B,QAAQ,KAAO,SAAU,GACnB,IAIJ,GAAa,EACb,EAAK,QAAS,EAKd,QAAQ,IAAM,WAAa,EAC3B,QAAQ,KAAO,WAAa,EAC5B,QAAQ,KAAO,WAAa,EAC5B,QAAQ,MAAQ,WAAa,EAE7B,EAAK,UAAS,WACZ,EAAY,EACd,IACF,EAGA,EAAK,KAAI,WACH,EAAK,OAEP,EAAK,OAAM,WACT,EAAK,SAAS,EAChB,IAEA,EAAK,SAAS,EAElB,GACF,EAEA,QAAU,OAAO,QAAU,IAAI","file":"/npm/shellcraft@1.3.9/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/shellcraft@1.3.9/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/* The MIT License (MIT)\n *\n * Copyright (c) 2014-2016 Xcraft <mathieu@schroetersa.ch>\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n'use strict';\n\nvar async = require('async');\nvar inquirer = require('inquirer');\nvar parse = require('shell-quote').parse;\n\nvar Command = require('./lib/command.js');\n\n/**\n * ShellCraft constructor.\n */\nfunction ShellCraft() {\n  var self = this;\n\n  var ArgumentsList = require('./lib/argumentslist.js');\n  var Prompt = require('./lib/prompt.js');\n\n  self._exit = false;\n  self._shell = true; /* open the shell be default */\n  self._scope = 'global';\n\n  self.arguments = new ArgumentsList();\n  self.arguments._add(\n    'exit',\n    new Command(\n      function (callback) {\n        self._exit = true;\n        if (callback) {\n          callback();\n        }\n      },\n      {builtIn: true, scope: '*'},\n      'exit the shell'\n    )\n  );\n\n  self.arguments._add(\n    'help',\n    new Command(\n      function (callback) {\n        Object.keys(Object.getPrototypeOf(self.arguments)).forEach(function (\n          fct\n        ) {\n          if (\n            !self.arguments.hasOwnProperty(fct) &&\n            !/^_/.test(fct) &&\n            self.arguments[fct].type() === 'command' &&\n            self.arguments[fct].isScoped(self._scope)\n          ) {\n            console.log(self.arguments[fct].help());\n          }\n        });\n\n        console.log('');\n\n        if (callback) {\n          callback();\n        }\n      },\n      {builtIn: true, scope: '*'},\n      'list of commands'\n    )\n  );\n\n  self.arguments._add(\n    'scope',\n    new Command(\n      function (callback, scope) {\n        self._scope = scope[0] || 'global';\n        self.autocomplete.reload();\n        self.prompt.setScope(self._scope !== 'global' ? scope : '');\n\n        if (callback) {\n          callback();\n        }\n      },\n      {\n        builtIn: true,\n        scope: '*',\n        params: {\n          optional: 'scope',\n        },\n      },\n      function () {\n        var help = 'change scope';\n        var scopes = [];\n\n        /* Look for all available scopes */\n        Object.keys(Object.getPrototypeOf(self.arguments)).forEach(function (\n          fct\n        ) {\n          if (\n            !self.arguments.hasOwnProperty(fct) &&\n            !/^_/.test(fct) &&\n            self.arguments[fct].type() === 'command'\n          ) {\n            var scope = self.arguments[fct].scope();\n            if (scope === '*' || scope === 'global') {\n              return;\n            }\n\n            if (scopes.indexOf(scope) === -1) {\n              scopes.push(self.arguments[fct].scope());\n            }\n          }\n        });\n\n        var list = scopes.length ? ' (' + scopes.join(', ') + ')' : '';\n        return help + list;\n      }\n    )\n  );\n\n  self.options = {\n    version: '0.0.1',\n  };\n  self.prompt = new Prompt();\n  self.extensions = {};\n\n  /* HACK inquirer prefix */\n  Object.keys(inquirer.prompt.prompts).forEach(function (prompt) {\n    inquirer.prompt.prompts[prompt].prototype.getQuestion = function () {\n      var msg = inquirer.prompt.prompts[\n        prompt\n      ].super_.prototype.getQuestion.bind(this)();\n      return msg.replace(/[^ ]*\\?[^ ]* /, '');\n    };\n  });\n}\n\n/**\n * Check if we must exit the shell.\n *\n * API private\n *\n * @returns {boolean} Exit status.\n */\nShellCraft.prototype.isExit = function () {\n  return this._exit;\n};\n\n/**\n * Start the Shell interface.\n *\n * API private\n *\n * @param {function(err, results)} callback\n */\nShellCraft.prototype.shell = function (callback) {\n  var self = this;\n\n  var util = require('util');\n  var AutoComplete = require('./lib/autocomplete.js');\n\n  if (self.options.prompt) {\n    self.prompt.setMessage(self.options.prompt);\n  }\n\n  var history = [];\n  var iterator = 0;\n\n  if (process.stdin.setRawMode) {\n    process.stdin.setRawMode(true);\n  }\n  self.uiPrompt = {};\n  self.autocomplete = new AutoComplete(self);\n\n  /* Try to keep the prompt always at the bottom.\n   * This feature is experimental and mostly based on:\n   *   http://stackoverflow.com/questions/12672193/fixed-position-command-prompt-in-node-js\n   */\n  var promptFixed = function () {\n    var con = {};\n    con.log = console.log;\n    con.warn = console.warn;\n    con.info = console.info;\n    con.error = console.error;\n\n    var fu = function (type, args) {\n      if (!self.uiPrompt.rl || !process.stdout.columns) {\n        return con[type].apply(con, args);\n      }\n\n      var t = Math.ceil(\n        (self.uiPrompt.rl.line.length + 3) / process.stdout.columns\n      );\n      var text = util.format.apply(console, args);\n\n      self.uiPrompt.rl.output.unmute();\n      self.uiPrompt.rl.output.write('\\n\\x1B[' + t + 'A\\x1B[0J');\n      self.uiPrompt.rl.output.write(text + '\\n');\n      self.uiPrompt.rl.output.write(new Array(t).join('\\n\\x1B[E'));\n      self.uiPrompt.rl._refreshLine();\n      self.uiPrompt.rl.output.mute();\n    };\n\n    console.log = function () {\n      fu('log', arguments);\n    };\n    console.warn = function () {\n      fu('warn', arguments);\n    };\n    console.info = function () {\n      fu('info', arguments);\n    };\n    console.error = function () {\n      fu('error', arguments);\n    };\n  };\n\n  if (self.options.promptFixed) {\n    promptFixed();\n  }\n\n  process.stdin.on('keypress', function (chunk, key) {\n    if (!key || !self.uiPrompt.rl) {\n      return;\n    }\n\n    switch (key.name) {\n      /* Command history */\n      case 'up': {\n        if (iterator > 0) {\n          --iterator;\n        }\n        self.uiPrompt.rl.write(null, {ctrl: true, name: 'u'});\n        self.uiPrompt.rl.write(history[iterator]);\n        break;\n      }\n      case 'down': {\n        self.uiPrompt.rl.write(null, {ctrl: true, name: 'u'});\n        if (iterator < history.length - 1) {\n          ++iterator;\n          self.uiPrompt.rl.write(history[iterator]);\n        } else {\n          iterator = history.length;\n        }\n        break;\n      }\n      /* Command auto-completion */\n      case 'tab': {\n        self.autocomplete.begin();\n        break;\n      }\n    }\n  });\n\n  var inquirerCallback = null;\n  var inquirerPrompt = self.prompt.getInquirer();\n\n  var prompt = inquirer.createPromptModule({\n    completer: function (line) {\n      return [[], line];\n    },\n  });\n\n  async.forever(\n    function (next) {\n      self.uiPrompt = prompt(inquirerPrompt, function (answers) {\n        /*\n         * Special handling when the command returns an Inquirer definition. In\n         * this case we must return the answers to the caller.\n         */\n        if (inquirerCallback) {\n          var returnToPrompt = inquirerCallback(answers);\n          if (returnToPrompt) {\n            inquirerCallback = null;\n            inquirerPrompt = self.prompt.getInquirer();\n            next();\n          }\n          return;\n        }\n\n        /*\n         * Normal shell handling for the commands.\n         */\n        var cmdArgs = parse(answers.command);\n        if (!cmdArgs.length) {\n          cmdArgs.push(answers.command);\n        }\n        var cmd = cmdArgs[0];\n        cmdArgs.shift();\n\n        if (cmd.length && answers.command !== history[history.length - 1]) {\n          history.push(answers.command);\n        }\n        iterator = history.length;\n\n        try {\n          if (!cmd.length) {\n            throw new Error();\n          }\n\n          if (\n            !Object.getPrototypeOf(self.arguments).hasOwnProperty(cmd) ||\n            /^_/.test(cmd)\n          ) {\n            throw new Error('command ' + cmd + ' unknown');\n          }\n\n          if (\n            self.arguments[cmd].type() !== 'command' ||\n            !self.arguments[cmd].isScoped(self._scope)\n          ) {\n            throw new Error(cmd + ' is not a command');\n          }\n\n          /* Check for required arguments. */\n          var required = self.arguments[cmd].getRequired();\n          required.forEach(function (req, index) {\n            if (!cmdArgs.length || !cmdArgs[index] || !cmdArgs[index].length) {\n              throw new Error('missing required argument `' + req + \"'\");\n            }\n          });\n\n          /* Check for optional arguments. */\n          var optional = self.arguments[cmd].getOptional();\n          if (!/[.]{3}$/.test(optional[optional.length - 1])) {\n            cmdArgs = cmdArgs.slice(0, required.length + optional.length);\n          }\n\n          self.arguments[cmd].call(function (data, wizardCallback) {\n            /* The next prompt we must start the wizard provided by the client. */\n            if (data) {\n              if (self.arguments[cmd].isWizard()) {\n                inquirerPrompt = data;\n                inquirerCallback = wizardCallback;\n              }\n            } else {\n              inquirerPrompt = self.prompt.getInquirer();\n              inquirerCallback = null;\n            }\n            next(self.isExit() ? 'good bye' : null);\n          }, cmdArgs);\n        } catch (ex) {\n          if (ex.message.length) {\n            console.log(ex.message);\n          }\n          next();\n        }\n      });\n    },\n    function (results) {\n      if (callback) {\n        callback(null, results);\n      }\n    }\n  );\n};\n\n/**\n * Start the Command Line Interface (CLI).\n *\n * API private\n *\n * @param {function(results)} callback\n */\nShellCraft.prototype.cli = function (callback) {\n  var self = this;\n  var scoped = false;\n  var program = require('commander');\n\n  program.version(self.options.version);\n\n  program\n    .command('*')\n    .description('')\n    .action(function (cmd) {\n      self._shell = false;\n      console.error('command ' + cmd + ' unknown');\n      if (callback) {\n        callback();\n      }\n    });\n\n  /* Include all scoped commands. */\n  program.option('-s, --scoped', 'include scoped commands (CLI only)');\n\n  var opts = program.normalize(process.argv.slice(2));\n  if (opts.indexOf('-s') !== -1 || opts.indexOf('--scoped') !== -1) {\n    scoped = true;\n  }\n\n  Object.keys(Object.getPrototypeOf(self.arguments)).forEach(function (fct) {\n    if (\n      /^_/.test(fct) ||\n      self.arguments[fct].isBuiltIn() ||\n      (!scoped && !self.arguments[fct].isScoped(self._scope))\n    ) {\n      return;\n    }\n\n    var params = self.arguments[fct].params();\n    var scope = self.arguments[fct].scope();\n\n    switch (scope) {\n      case '*':\n      case 'global': {\n        scope = '';\n        break;\n      }\n      default: {\n        scope += '@';\n        break;\n      }\n    }\n\n    switch (self.arguments[fct].type()) {\n      case 'option': {\n        program.option(\n          fct + params,\n          self.arguments[fct].help(true),\n          function () {\n            var args = arguments;\n\n            /* We force to only one argument with the options. */\n            if (args.length > 1) {\n              args = [args[0]];\n            }\n            self.arguments[fct].call(function () {}, args);\n          }\n        );\n        return;\n      }\n      case 'command': {\n        program\n          .command(scope + fct + params)\n          .description(self.arguments[fct].help(true))\n          .action(function () {\n            self._shell = false;\n\n            var values = [];\n\n            Array.prototype.slice\n              .call(arguments)\n              .filter(function (arg) {\n                return arg !== undefined;\n              })\n              .forEach(function (arg) {\n                if (Array.isArray(arg)) {\n                  values = values.concat(arg);\n                  return;\n                }\n\n                if (typeof arg === 'object') {\n                  return;\n                }\n\n                values.push(arg);\n              });\n\n            self.arguments[fct].call(function (data, wizardCallback) {\n              if (!data || !self.arguments[fct].isWizard()) {\n                if (callback) {\n                  callback();\n                }\n                return;\n              }\n\n              /* Start the wizard. */\n              inquirer.prompt(data, function (answers) {\n                var stop = wizardCallback(answers);\n                if (stop && callback) {\n                  callback();\n                }\n              });\n            }, values);\n          });\n        return;\n      }\n      default: {\n        callback(\n          'item ' +\n            fct +\n            ' is ' +\n            self.arguments[fct].type() +\n            ' but a command or an option was expected'\n        );\n        return;\n      }\n    }\n  });\n\n  program.parse(process.argv);\n\n  if (!program.args.length && callback) {\n    callback();\n  }\n};\n\n/**\n * Close the Command Line Interface (CLI) or the shell.\n *\n * API private\n *\n * @param {function(err)} callback\n */\nShellCraft.prototype.shutdown = function (callback) {\n  var self = this;\n  async.each(\n    Object.keys(self.extensions),\n    function (ext, callback) {\n      self.extensions[ext].unregister(callback);\n    },\n    function (err) {\n      callback(err);\n    }\n  );\n};\n\n/**\n * Register external commands.\n *\n * @param {string} shellExt - Path on the shell extension file.\n * @param {function(err)} callback\n */\nShellCraft.prototype.registerExtension = function (shellExt, callback) {\n  var self = this;\n  var path = require('path');\n  var ext = require(shellExt);\n\n  var Extension = require('./lib/extension.js');\n  var extension = new Extension(self);\n\n  ext.register(extension, function (err) {\n    if (!err) {\n      self.extensions[path.resolve(shellExt)] = ext;\n      if (self.autocomplete) {\n        self.autocomplete.reload();\n      }\n    }\n\n    if (callback) {\n      callback(err);\n    }\n  });\n};\n\n/**\n * Begins the Shell or the CLI accordingly to the provided arguments.\n *\n * @param {Object} options\n * @param {function(err, results)} callback\n */\nShellCraft.prototype.begin = function (options, callback) {\n  var self = this;\n  self.options = options;\n\n  /* HACK: This is ugly but the problem comes from Commander which is abusing\n   * of process.exit.\n   */\n  var terminated = false;\n  var processExit = process.exit;\n  process.exit = function (code) {\n    if (terminated) {\n      return;\n    }\n\n    terminated = true;\n    self._shell = false;\n\n    /* HACK: Commander considers that -h, --help is not recognized.\n     * It's related to the abuse of process.exit.\n     */\n    console.log = function () {};\n    console.warn = function () {};\n    console.info = function () {};\n    console.error = function () {};\n\n    self.shutdown(function () {\n      processExit(code);\n    });\n  };\n\n  /* Run in command line. */\n  self.cli(function () {\n    if (self._shell) {\n      /* Run the Shell. */\n      self.shell(function () {\n        self.shutdown(callback);\n      });\n    } else {\n      self.shutdown(callback);\n    }\n  });\n};\n\nexports = module.exports = new ShellCraft();\n"]}