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AAS,GAAK,EAAO,QAAQ,WAAa,KAC3D,EAAQ,KAAK,aACb,QAAQ,KAAK,IAGf,EAAQ,MAAM,MAAK,QAAW,OAAM,GAAO,KAAK,QAAQ,MAAM,IAChE,EAGF,OAAO,QAAU","file":"/npm/terraform-plus@0.0.12/src/terraform-plus.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/terraform-plus@0.0.12/src/terraform-plus.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nconst cli = require('commander');\n\nconst inquirer = require('inquirer');\nconst autocomplete = require('inquirer-autocomplete-prompt');\nconst pjson = require('../package');\nconst AbstractCommand = require('./abstract-command');\n\nclass TerraformPlus {\n\n  construct() {\n    this._currentCommand = null;\n    this._logger = null;\n  }\n\n  /**\n   * @desc\n   * Run tfs [command] [options] [arguments]\n   *\n   * @example\n   * let tfs = new TerraformPlus();\n   * tfs.run(process.argv);\n   *\n   * @param {Array} commandLine - entire command line passed to cli\n   */\n  run(commandLine) {\n    // customize default indentation\n    this._defaultIndentation();\n\n    // setup cli version\n    cli.version(pjson.version);\n\n    // parse and remove global options from command line\n    let parsed = commandLine.slice(2);\n    let options = [ '-V', '--version', '-v', '--verbose', '-w', '--verbose2' ];\n    for (let i = parsed.length; i > 0; i--) {\n      if (options.includes(parsed[i - 1])) {\n        parsed.splice(i - 1, 1);\n      }\n    }\n\n    // check for potential command name\n    if (parsed.length > 0) {\n\n      // validate that command name is supported\n      this._parseCommand(parsed);\n\n      // remove command from parsed command line\n      //parsed = parsed.slice(1);\n    }\n\n    // no command provided\n    else {\n\n      // setup default command\n      this._defaultCommand();\n    }\n\n    // finish specifying commands, options and arguments, and parse the whole thing\n    cli.arguments('[arguments]')\n      .option('-v, --verbose', 'output warning messages by enabling verbose mode')\n      .option('-w, --verbose2', 'output debugging messages by enabling verbose2 mode')\n      .parse(commandLine);\n\n    // enable verbose or debug logging capabilities\n    if (cli.verbose) {\n      this._logger.setLevel(this._logger.WARN);\n    } else if (cli.verbose2) {\n      this._logger.setLevel(this._logger.DEBUG);\n    }\n\n    // if no options, output help\n    let showHelp = ((parsed.length <= 1 && parsed[0] === 'create') || parsed.length === 0);\n\n    if (showHelp) {\n      cli.outputHelp();\n      process.exit(0);\n    }\n  }\n\n  /**\n   * @private\n   */\n  _defaultIndentation() {\n    const helpInformation = cli.Command.prototype.helpInformation;\n    const indentation = '  ';\n\n    cli.Command.prototype.helpInformation = function () {\n      return helpInformation.call(this)\n        .split(/^/m)\n        .reduce((accum, line) => {\n          if (line === '\\n') {\n            const lastLine = accum[accum.length - 1];\n            if (!lastLine || !(lastLine === '\\n' || lastLine.endsWith(':\\n'))) {\n              accum.push(line);\n            }\n          } else {\n            accum.push(line.substr(indentation.length));\n          }\n\n          return accum;\n        }, [])\n        .join('');\n    }\n  }\n\n  /**\n   * @private\n   */\n  _defaultCommand() {\n    // setup command action and description\n    cli.usage(`[command] [options] [arguments]`)\n      .description(`tfs@${pjson.version} (built: ${pjson.buildDate})\\n  ${pjson.description}`);\n\n    // setup command options\n    AbstractCommand.COMMANDS_LIST.forEach(command => {\n      if (typeof command !== 'undefined') {\n        cli.command(command.name)\n          .description(command.description);\n      }\n    });\n\n    // customize help output\n    cli.on('--help', function() {\n      console.log(`\\nUse \"tfs [command] --help\" for more information about [command]`);\n    });\n\n    // enable default logging capabilities\n    this._logger = AbstractCommand.LOGGER;\n  }\n\n  /**\n   * @desc Validates passed command name and set up it.\n   *\n   * @param {Array} parsed\n   *\n   * @private\n   */\n  _parseCommand(parsed) {\n    // validate that command name is supported\n\n    if (AbstractCommand.COMMANDS_LIST.map(key => key.name).includes(parsed[0])) {\n      this._currentCommand = parsed[0];\n\n      // setup command specific action and description\n      const CommandClass = require(`${AbstractCommand.COMMANDS_PATH}/${this._currentCommand}`);\n      cli.usage(`${parsed[0]} [options] [arguments]`)\n        .description(`tfs@${pjson.version} (built: ${pjson.buildDate})\n  tfs ${this._currentCommand} will ${CommandClass.DESCRIPTION}`);\n\n      if ((parsed.length >= 1 && parsed[0] !== 'create') || (parsed.length > 1 && parsed[0] === 'create')) {\n        cli.action(commandName => { this._runCommand(commandName, parsed) });\n      }\n\n      // setup command specific options\n      CommandClass.OPTIONS.forEach(option => {\n        if (option.hasOwnProperty('collect')) {\n          cli.option(option.opt, option.desc, this.collect, []);\n        }\n        else {\n          cli.option(option.opt, option.desc);\n        }\n      });\n\n      // enable default logging capabilities\n      this._logger = CommandClass.LOGGER;\n    }\n\n    // command name is NOT supported\n    else {\n      console.log(`'${parsed[0]}' is not a valid tfs command`);\n      console.log(`Use 'tfs --help' to see supported list of commands.`);\n\n      process.exit(1);\n    }\n  }\n\n  /**\n   *\n   * @param {String} val\n   * @param {Array} memo\n   * @return {*}\n   */\n  collect(val, memo) {\n    memo.push(val);\n    return memo;\n  }\n\n  /**\n   * Runs dynamicly tfs [command]\n   * @param {String} commandName\n   * @param {Object} parsed\n   * @private\n   */\n  async _runCommand(commandName, parsed) {\n    const CommandClass = require(`${AbstractCommand.COMMANDS_PATH}/${commandName}`);\n    const command = new CommandClass(cli, parsed);\n\n    if (!(command instanceof AbstractCommand)) {\n      throw new Error(`${commandName} must be an implementation of AbstractCommand class`);\n    }\n\n    if (command._cli.interactive) {\n      inquirer.registerPrompt('autocomplete', autocomplete);\n      await inquirer.prompt(CommandClass.QUESTIONS).then(answers => {\n        // Use user feedback for ... whatever!!\n        command.promt(answers);\n        //command.run();\n      });\n    }\n\n    if (parsed.indexOf('-h') > -1 || parsed.indexOf('--help') > -1) {\n      command._cli.outputHelp();\n      process.exit(0);\n    }\n\n    command.run().then(res => {}).catch(err => this._logger.error(err));\n  }\n}\n\nmodule.exports = TerraformPlus;\n"]}