/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/shellcraft@1.3.9/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var async=require("async"),inquirer=require("inquirer"),parse=require("shell-quote").parse,Command=require("./lib/command.js");function ShellCraft(){var e=this,t=require("./lib/argumentslist.js"),o=require("./lib/prompt.js");e._exit=!1,e._shell=!0,e._scope="global",e.arguments=new t,e.arguments._add("exit",new Command((function(t){e._exit=!0,t&&t()}),{builtIn:!0,scope:"*"},"exit the shell")),e.arguments._add("help",new Command((function(t){Object.keys(Object.getPrototypeOf(e.arguments)).forEach((function(t){e.arguments.hasOwnProperty(t)||/^_/.test(t)||"command"!==e.arguments[t].type()||!e.arguments[t].isScoped(e._scope)||console.log(e.arguments[t].help())})),console.log(""),t&&t()}),{builtIn:!0,scope:"*"},"list of commands")),e.arguments._add("scope",new Command((function(t,o){e._scope=o[0]||"global",e.autocomplete.reload(),e.prompt.setScope("global"!==e._scope?o:""),t&&t()}),{builtIn:!0,scope:"*",params:{optional:"scope"}},(function(){var t=[];return Object.keys(Object.getPrototypeOf(e.arguments)).forEach((function(o){if(!e.arguments.hasOwnProperty(o)&&!/^_/.test(o)&&"command"===e.arguments[o].type()){var n=e.arguments[o].scope();if("*"===n||"global"===n)return;-1===t.indexOf(n)&&t.push(e.arguments[o].scope())}})),"change scope"+(t.length?" ("+t.join(", ")+")":"")}))),e.options={version:"0.0.1"},e.prompt=new o,e.extensions={},Object.keys(inquirer.prompt.prompts).forEach((function(e){inquirer.prompt.prompts[e].prototype.getQuestion=function(){return inquirer.prompt.prompts[e].super_.prototype.getQuestion.bind(this)().replace(/[^ ]*\?[^ ]* /,"")}}))}ShellCraft.prototype.isExit=function(){return this._exit},ShellCraft.prototype.shell=function(e){var t=this,o=require("util"),n=require("./lib/autocomplete.js");t.options.prompt&&t.prompt.setMessage(t.options.prompt);var r=[],s=0;process.stdin.setRawMode&&process.stdin.setRawMode(!0),t.uiPrompt={},t.autocomplete=new n(t);t.options.promptFixed&&function(){var e={};e.log=console.log,e.warn=console.warn,e.info=console.info,e.error=console.error;var n=function(n,r){if(!t.uiPrompt.rl||!process.stdout.columns)return e[n].apply(e,r);var s=Math.ceil((t.uiPrompt.rl.line.length+3)/process.stdout.columns),i=o.format.apply(console,r);t.uiPrompt.rl.output.unmute(),t.uiPrompt.rl.output.write("\n["+s+"A[0J"),t.uiPrompt.rl.output.write(i+"\n"),t.uiPrompt.rl.output.write(new Array(s).join("\n[E")),t.uiPrompt.rl._refreshLine(),t.uiPrompt.rl.output.mute()};console.log=function(){n("log",arguments)},console.warn=function(){n("warn",arguments)},console.info=function(){n("info",arguments)},console.error=function(){n("error",arguments)}}(),process.stdin.on("keypress",(function(e,o){if(o&&t.uiPrompt.rl)switch(o.name){case"up":s>0&&--s,t.uiPrompt.rl.write(null,{ctrl:!0,name:"u"}),t.uiPrompt.rl.write(r[s]);break;case"down":t.uiPrompt.rl.write(null,{ctrl:!0,name:"u"}),s<r.length-1?(++s,t.uiPrompt.rl.write(r[s])):s=r.length;break;case"tab":t.autocomplete.begin()}}));var i=null,u=t.prompt.getInquirer(),a=inquirer.createPromptModule({completer:function(e){return[[],e]}});async.forever((function(e){t.uiPrompt=a(u,(function(o){if(i){i(o)&&(i=null,u=t.prompt.getInquirer(),e())}else{var n=parse(o.command);n.length||n.push(o.command);var a=n[0];n.shift(),a.length&&o.command!==r[r.length-1]&&r.push(o.command),s=r.length;try{if(!a.length)throw new Error;if(!Object.getPrototypeOf(t.arguments).hasOwnProperty(a)||/^_/.test(a))throw new Error("command "+a+" unknown");if("command"!==t.arguments[a].type()||!t.arguments[a].isScoped(t._scope))throw new Error(a+" is not a command");var c=t.arguments[a].getRequired();c.forEach((function(e,t){if(!n.length||!n[t]||!n[t].length)throw new Error("missing required argument `"+e+"'")}));var l=t.arguments[a].getOptional();/[.]{3}$/.test(l[l.length-1])||(n=n.slice(0,c.length+l.length)),t.arguments[a].call((function(o,n){o?t.arguments[a].isWizard()&&(u=o,i=n):(u=t.prompt.getInquirer(),i=null),e(t.isExit()?"good bye":null)}),n)}catch(t){t.message.length&&console.log(t.message),e()}}}))}),(function(t){e&&e(null,t)}))},ShellCraft.prototype.cli=function(e){var t=this,o=!1,n=require("commander");n.version(t.options.version),n.command("*").description("").action((function(o){t._shell=!1,console.error("command "+o+" unknown"),e&&e()})),n.option("-s, --scoped","include scoped commands (CLI only)");var r=n.normalize(process.argv.slice(2));-1===r.indexOf("-s")&&-1===r.indexOf("--scoped")||(o=!0),Object.keys(Object.getPrototypeOf(t.arguments)).forEach((function(r){if(!/^_/.test(r)&&!t.arguments[r].isBuiltIn()&&(o||t.arguments[r].isScoped(t._scope))){var s=t.arguments[r].params(),i=t.arguments[r].scope();switch(i){case"*":case"global":i="";break;default:i+="@"}switch(t.arguments[r].type()){case"option":return void n.option(r+s,t.arguments[r].help(!0),(function(){var e=arguments;e.length>1&&(e=[e[0]]),t.arguments[r].call((function(){}),e)}));case"command":return void n.command(i+r+s).description(t.arguments[r].help(!0)).action((function(){t._shell=!1;var o=[];Array.prototype.slice.call(arguments).filter((function(e){return void 0!==e})).forEach((function(e){Array.isArray(e)?o=o.concat(e):"object"!=typeof e&&o.push(e)})),t.arguments[r].call((function(o,n){o&&t.arguments[r].isWizard()?inquirer.prompt(o,(function(t){n(t)&&e&&e()})):e&&e()}),o)}));default:return void e("item "+r+" is "+t.arguments[r].type()+" but a command or an option was expected")}}})),n.parse(process.argv),!n.args.length&&e&&e()},ShellCraft.prototype.shutdown=function(e){var t=this;async.each(Object.keys(t.extensions),(function(e,o){t.extensions[e].unregister(o)}),(function(t){e(t)}))},ShellCraft.prototype.registerExtension=function(e,t){var o=this,n=require("path"),r=require(e),s=new(require("./lib/extension.js"))(o);r.register(s,(function(s){s||(o.extensions[n.resolve(e)]=r,o.autocomplete&&o.autocomplete.reload()),t&&t(s)}))},ShellCraft.prototype.begin=function(e,t){var o=this;o.options=e;var n=!1,r=process.exit;process.exit=function(e){n||(n=!0,o._shell=!1,console.log=function(){},console.warn=function(){},console.info=function(){},console.error=function(){},o.shutdown((function(){r(e)})))},o.cli((function(){o._shell?o.shell((function(){o.shutdown(t)})):o.shutdown(t)}))},exports=module.exports=new ShellCraft;
//# sourceMappingURL=/sm/e8da4ef1eba4e44cdbf6f2c655277ae0d8f44ae5d5f010f8a27a55a91fa7ada8.map