MCPcopy Create free account
hub / github.com/ChinaSiro/claude-code-sourcemap / version

Method version

package/cli.js:7945–7946  ·  view source on GitHub ↗
(q,K,_)

Source from the content-addressed store, hash-verified

7943 - ${H}`;throw Error(J)}else if(j.code==="EACCES")throw Error(`'${$}' not executable`);if(!w)pJ.exit(1);else{let H=new i_7(1,"commander.executeSubCommandAsync","(error)");H.nestedError=j,w(H)}}),this.runningCommand=O}_dispatchSubcommand(q,K,_){let z=this._findCommand(q);if(!z)this.help({error:!0});let Y;return Y=this._chainOrCallSubCommandHook(Y,z,"preSubcommand"),Y=this._chainOrCall(Y,()=>{if(z._executableHandler)this._executeSubCommand(z,K.concat(_));else return z._parseCommand(K,_)}),Y}_dispatchHelpCommand(q){if(!q)this.help();let K=this._findCommand(q);if(K&&!K._executableHandler)K.help();return this._dispatchSubcommand(q,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){if(this.registeredArguments.forEach((q,K)=>{if(q.required&&this.args[K]==null)this.missingArgument(q.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)return;if(this.args.length>this.registeredArguments.length)this._excessArguments(this.args)}_processArguments(){let q=(_,z,Y)=>{let $=z;if(z!==null&&_.parseArg){let A=`error: command-argument value '${z}' is invalid for argument '${_.name()}'.`;$=this._callParseArg(_,z,Y,A)}return $};this._checkNumberOfArguments();let K=[];this.registeredArguments.forEach((_,z)=>{let Y=_.defaultValue;if(_.variadic){if(z<this.args.length){if(Y=this.args.slice(z),_.parseArg)Y=Y.reduce(($,A)=>{return q(_,A,$)},_.defaultValue)}else if(Y===void 0)Y=[]}else if(z<this.args.length){if(Y=this.args[z],_.parseArg)Y=q(_,Y,_.defaultValue)}K[z]=Y}),this.processedArgs=K}_chainOrCall(q,K){if(q&&q.then&&typeof q.then==="function")return q.then(()=>K());return K()}_chainOrCallHooks(q,K){let _=q,z=[];if(this._getCommandAndAncestors().reverse().filter((Y)=>Y._lifeCycleHooks[K]!==void 0).forEach((Y)=>{Y._lifeCycleHooks[K].forEach(($)=>{z.push({hookedCommand:Y,callback:$})})}),K==="postAction")z.reverse();return z.forEach((Y)=>{_=this._chainOrCall(_,()=>{return Y.callback(Y.hookedCommand,this)})}),_}_chainOrCallSubCommandHook(q,K,_){let z=q;if(this._lifeCycleHooks[_]!==void 0)this._lifeCycleHooks[_].forEach((Y)=>{z=this._chainOrCall(z,()=>{return Y(this,K)})});return z}_parseCommand(q,K){let _=this.parseOptions(K);if(this._parseOptionsEnv(),this._parseOptionsImplied(),q=q.concat(_.operands),K=_.unknown,this.args=q.concat(K),q&&this._findCommand(q[0]))return this._dispatchSubcommand(q[0],q.slice(1),K);if(this._getHelpCommand()&&q[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(q[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(K),this._dispatchSubcommand(this._defaultCommandName,q,K);if(this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName)this.help({error:!0});this._outputHelpIfRequested(_.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let z=()=>{if(_.unknown.length>0)this.unknownOption(_.unknown[0])},Y=`command:${this.name()}`;if(this._actionHandler){z(),this._processArguments();let $;if($=this._chainOrCallHooks($,"preAction"),$=this._chainOrCall($,()=>this._actionHandler(this.processedArgs)),this.parent)$=this._chainOrCall($,()=>{this.parent.emit(Y,q,K)});return $=this._chainOrCallHooks($,"postAction"),$}if(this.parent&&this.parent.listenerCount(Y))z(),this._processArguments(),this.parent.emit(Y,q,K);else if(q.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",q,K);if(this.listenerCount("command:*"))this.emit("command:*",q,K);else if(this.commands.length)this.unknownCommand();else z(),this._processArguments()}else if(this.commands.length)z(),this.help({error:!0});else z(),this._processArguments()}_findCommand(q){if(!q)return;return this.commands.find((K)=>K._name===q||K._aliases.includes(q))}_findOption(q){return this.options.find((K)=>K.is(q))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach((q)=>{q.options.forEach((K)=>{if(K.mandatory&&q.getOptionValue(K.attributeName())===void 0)q.missingMandatoryOptionValue(K)})})}_checkForConflictingLocalOptions(){let q=this.options.filter((_)=>{let z=_.attributeName();if(this.getOptionValue(z)===void 0)return!1;return this.getOptionValueSource(z)!=="default"});q.filter((_)=>_.conflictsWith.length>0).forEach((_)=>{let z=q.find((Y)=>_.conflictsWith.includes(Y.attributeName()));if(z)this._conflictingOption(_,z)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach((q)=>{q._checkForConflictingLocalOptions()})}parseOptions(q){let K=[],_=[],z=K,Y=q.slice();function $(O){return O.length>1&&O[0]==="-"}let A=null;while(Y.length){let O=Y.shift();if(O==="--"){if(z===_)z.push(O);z.push(...Y);break}if(A&&!$(O)){this.emit(`option:${A.name()}`,O);continue}if(A=null,$(O)){let w=this._findOption(O);if(w){if(w.required){let j=Y.shift();if(j===void 0)this.optionMissingArgument(w);this.emit(`option:${w.name()}`,j)}else if(w.optional){let j=null;if(Y.length>0&&!$(Y[0]))j=Y.shift();this.emit(`option:${w.name()}`,j)}else this.emit(`option:${w.name()}`);A=w.variadic?w:null;continue}}if(O.length>2&&O[0]==="-"&&O[1]!=="-"){let w=this._findOption(`-${O[1]}`);if(w){if(w.required||w.optional&&this._combineFlagAndOptionalValue)this.emit(`option:${w.name()}`,O.slice(2));else this.emit(`option:${w.name()}`),Y.unshift(`-${O.slice(2)}`);continue}}if(/^--[^=]+=/.test(O)){let w=O.indexOf("="),j=this._findOption(O.slice(0,w));if(j&&(j.required||j.optional)){this.emit(`option:${j.name()}`,O.slice(w+1));continue}}if($(O))z=_;if((this._enablePositionalOptions||this._passThroughOptions)&&K.length===0&&_.length===0){if(this._findCommand(O)){if(K.push(O),Y.length>0)_.push(...Y);break}else if(this._getHelpCommand()&&O===this._getHelpCommand().name()){if(K.push(O),Y.length>0)K.push(...Y);break}else if(this._defaultCommandName){if(_.push(O),Y.length>0)_.push(...Y);break}}if(this._passThroughOptions){if(z.push(O),Y.length>0)z.push(...Y);break}z.push(O)}return{operands:K,unknown:_}}opts(){if(this._storeOptionsAsProperties){let q={},K=this.options.length;for(let _=0;_<K;_++){let z=this.options[_].attributeName();q[z]=z===this._versionOptionName?this._version:this[z]}return q}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((q,K)=>Object.assign(q,K.opts()),{})}error(q,K){if(this._outputConfiguration.outputError(`${q}
7944`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==="string")this._outputConfiguration.writeErr(`${this._showHelpAfterError}
7945`);else if(this._showHelpAfterError)this._outputConfiguration.writeErr(`
7946`),this.outputHelp({error:!0});let _=K||{},z=_.exitCode||1,Y=_.code||"commander.error";this._exit(z,Y,q)}_parseOptionsEnv(){this.options.forEach((q)=>{if(q.envVar&&q.envVar in pJ.env){let K=q.attributeName();if(this.getOptionValue(K)===void 0||["default","config","env"].includes(this.getOptionValueSource(K)))if(q.required||q.optional)this.emit(`optionEnv:${q.name()}`,pJ.env[q.envVar]);else this.emit(`optionEnv:${q.name()}`)}})}_parseOptionsImplied(){let q=new lbY(this.options),K=(_)=>{return this.getOptionValue(_)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(_))};this.options.filter((_)=>_.implied!==void 0&&K(_.attributeName())&&q.valueFromOption(this.getOptionValue(_.attributeName()),_)).forEach((_)=>{Object.keys(_.implied).filter((z)=>!K(z)).forEach((z)=>{this.setOptionValueWithSource(z,_.implied[z],"implied")})})}missingArgument(q){let K=`error: missing required argument '${q}'`;this.error(K,{code:"commander.missingArgument"})}optionMissingArgument(q){let K=`error: option '${q.flags}' argument missing`;this.error(K,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(q){let K=`error: required option '${q.flags}' not specified`;this.error(K,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(q,K){let _=($)=>{let A=$.attributeName(),O=this.getOptionValue(A),w=this.options.find((H)=>H.negate&&A===H.attributeName()),j=this.options.find((H)=>!H.negate&&A===H.attributeName());if(w&&(w.presetArg===void 0&&O===!1||w.presetArg!==void 0&&O===w.presetArg))return w;return j||$},z=($)=>{let A=_($),O=A.attributeName();if(this.getOptionValueSource(O)==="env")return`environment variable '${A.envVar}'`;return`option '${A.flags}'`},Y=`error: ${z(q)} cannot be used with ${z(K)}`;this.error(Y,{code:"commander.conflictingOption"})}unknownOption(q){if(this._allowUnknownOption)return;let K="";if(q.startsWith("--")&&this._showSuggestionAfterError){let z=[],Y=this;do{let $=Y.createHelp().visibleOptions(Y).filter((A)=>A.long).map((A)=>A.long);z=z.concat($),Y=Y.parent}while(Y&&!Y._enablePositionalOptions);K=nFK(q,z)}let _=`error: unknown option '${q}'${K}`;this.error(_,{code:"commander.unknownOption"})}_excessArguments(q){if(this._allowExcessArguments)return;let K=this.registeredArguments.length,_=K===1?"":"s",Y=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${K} argument${_} but got ${q.length}.`;this.error(Y,{code:"commander.excessArguments"})}unknownCommand(){let q=this.args[0],K="";if(this._showSuggestionAfterError){let z=[];this.createHelp().visibleCommands(this).forEach((Y)=>{if(z.push(Y.name()),Y.alias())z.push(Y.alias())}),K=nFK(q,z)}let _=`error: unknown command '${q}'${K}`;this.error(_,{code:"commander.unknownCommand"})}version(q,K,_){if(q===void 0)return this._version;this._version=q,K=K||"-V, --version",_=_||"output the version number";let z=this.createOption(K,_);return this._versionOptionName=z.attributeName(),this._registerOption(z),this.on("option:"+z.name(),()=>{this._outputConfiguration.writeOut(`${q}
7947`),this._exit(0,"commander.version",q)}),this}description(q,K){if(q===void 0&&K===void 0)return this._description;if(this._description=q,K)this._argsDescription=K;return this}summary(q){if(q===void 0)return this._summary;return this._summary=q,this}alias(q){if(q===void 0)return this._aliases[0];let K=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)K=this.commands[this.commands.length-1];if(q===K._name)throw Error("Command alias can't be the same as its name");let _=this.parent?._findCommand(q);if(_){let z=[_.name()].concat(_.aliases()).join("|");throw Error(`cannot add alias '${q}' to command '${this.name()}' as already have command '${z}'`)}return K._aliases.push(q),this}aliases(q){if(q===void 0)return this._aliases;return q.forEach((K)=>this.alias(K)),this}usage(q){if(q===void 0){if(this._usage)return this._usage;let K=this.registeredArguments.map((_)=>{return dbY(_)});return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?K:[]).join(" ")}return this._usage=q,this}name(q){if(q===void 0)return this._name;return this._name=q,this}nameFromFilename(q){return this._name=hs.basename(q,hs.extname(q)),this}executableDir(q){if(q===void 0)return this._executableDir;return this._executableDir=q,this}helpInformation(q){let K=this.createHelp();if(K.helpWidth===void 0)K.helpWidth=q&&q.error?this._outputConfiguration.getErrHelpWidth():this._outputConfiguration.getOutHelpWidth();return K.formatHelp(this,K)}_getHelpContext(q){q=q||{};let K={error:!!q.error},_;if(K.error)_=(z)=>this._outputConfiguration.writeErr(z);else _=(z)=>this._outputConfiguration.writeOut(z);return K.write=q.write||_,K.command=this,K}outputHelp(q){let K;if(typeof q==="function")K=q,q=void 0;let _=this._getHelpContext(q);this._getCommandAndAncestors().reverse().forEach((Y)=>Y.emit("beforeAllHelp",_)),this.emit("beforeHelp",_);let z=this.helpInformation(_);if(K){if(z=K(z),typeof z!=="string"&&!Buffer.isBuffer(z))throw Error("outputHelp callback must return a string or a Buffer")}if(_.write(z),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",_),this._getCommandAndAncestors().forEach((Y)=>Y.emit("afterAllHelp",_))}helpOption(q,K){if(typeof q==="boolean"){if(q)this._helpOption=this._helpOption??void 0;else this._helpOption=null;return this}return q=q??"-h, --help",K=K??"display help for command",this._helpOption=this.createOption(q,K),this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption(q){return this._helpOption=q,this}help(q){this.outputHelp(q);let K=pJ.exitCode||0;if(K===0&&q&&typeof q!=="function"&&q.error)K=1;this._exit(K,"commander.help","(outputHelp)")}addHelpText(q,K){let _=["beforeAll","before","after","afterAll"];if(!_.includes(q))throw Error(`Unexpected value for position to addHelpText.
7948Expecting one of '${_.join("', '")}'`);let z=`${q}Help`;return this.on(z,(Y)=>{let $;if(typeof K==="function")$=K({error:Y.error,command:Y.command});else $=K;if($)Y.write(`${$}
7949`)}),this}_outputHelpIfRequested(q){let K=this._getHelpOption();if(K&&q.find((z)=>K.is(z)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function iFK(q){return q.map((K)=>{if(!K.startsWith("--inspect"))return K;let _,z="127.0.0.1",Y="9229",$;if(($=K.match(/^(--inspect(-brk)?)$/))!==null)_=$[1];else if(($=K.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(_=$[1],/^\d+$/.test($[3]))Y=$[3];else z=$[3];else if(($=K.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)_=$[1],z=$[3],Y=$[4];if(_&&Y!=="0")return`${_}=${z}:${parseInt(Y)+1}`;return K})}nbY.Command=r_7});var tFK=m((abY)=>{var{Argument:oFK}=iQ8(),{Command:o_7}=rFK(),{CommanderError:rbY,InvalidArgumentError:aFK}=eq8(),{Help:obY}=d_7(),{Option:sFK}=c_7();abY.program=new o_7;abY.createCommand=(q)=>new o_7(q);abY.createOption=(q,K)=>new sFK(q,K);abY.createArgument=(q,K)=>new oFK(q,K);abY.Command=o_7;abY.Option=sFK;abY.Argument=oFK;abY.Help=obY;abY.CommanderError=rbY;abY.InvalidArgumentError=aFK;abY.InvalidOptionArgumentError=aFK});var qUK=m((kR,eFK)=>{var hp=tFK();kR=eFK.exports={};kR.program=new hp.Command;kR.Argument=hp.Argument;kR.Command=hp.Command;kR.CommanderError=hp.CommanderError;kR.Help=hp.Help;kR.InvalidArgumentError=hp.InvalidArgumentError;kR.InvalidOptionArgumentError=hp.InvalidArgumentError;kR.Option=hp.Option;kR.createCommand=(q)=>new hp.Command(q);kR.createOption=(q,K)=>new hp.Option(q,K);kR.createArgument=(q,K)=>new hp.Argument(q,K)});var KUK,le2,ne2,ie2,re2,oe2,_UK,ae2,zUK,se2,G3,te2;var a_7=y(()=>{KUK=O6(qUK(),1),{program:le2,createCommand:ne2,createArgument:ie2,createOption:re2,CommanderError:oe2,InvalidArgumentError:_UK,InvalidOptionArgumentError:ae2,Command:zUK,Argument:se2,Option:G3,Help:te2}=KUK.default});function $UK(){if(YUK)return;if(YUK=!0,i6(process.env.CLAUDE_CODE_USE_BEDROCK)||i6(process.env.CLAUDE_CODE_USE_VERTEX)||i6(process.env.CLAUDE_CODE_USE_FOUNDRY))return;if(process.env.HTTPS_PROXY||process.env.https_proxy||process.env.HTTP_PROXY||process.env.http_proxy||process.env.ANTHROPIC_UNIX_SOCKET||process.env.CLAUDE_CODE_CLIENT_CERT||process.env.CLAUDE_CODE_CLIENT_KEY)return;let q=process.env.ANTHROPIC_BASE_URL||u7().BASE_API_URL;fetch(q,{method:"HEAD",signal:AbortSignal.timeout(1e4)}).catch(()=>{})}var YUK=!1;var AUK=y(()=>{H3();m8()});function OUK(){if(process.env.NODE_EXTRA_CA_CERTS)return;let q=wxY();if(q)process.env.NODE_EXTRA_CA_CERTS=q,N(`CA certs: Applied NODE_EXTRA_CA_CERTS from config to process.env: ${q}`)}function wxY(){try{let K=j8()?.env,z=v1("userSettings")?.env;N(`CA certs: Config fallback - globalEnv keys: ${K?Object.keys(K).join(","):"none"}, settingsEnv keys: ${z?Object.keys(z).join(","):"none"}`);let Y=z?.NODE_EXTRA_CA_CERTS||K?.NODE_EXTRA_CA_CERTS;if(Y)N(`CA certs: Found NODE_EXTRA_CA_CERTS in config/settings: ${Y}`);return Y}catch(q){N(`CA certs: Config fallback failed: ${q}`,{level:"error"});return}}var wUK=y(()=>{V1();_8();U1()});function jxY(q){if(!q||!process.env.ANTHROPIC_UNIX_SOCKET)return q||{};let{ANTHROPIC_UNIX_SOCKET:K,ANTHROPIC_BASE_URL:_,ANTHROPIC_API_KEY:z,ANTHROPIC_AUTH_TOKEN:Y,CLAUDE_CODE_OAUTH_TOKEN:$,...A}=q;return A}function HxY(q){if(!q)return{};if(!i6(process.env.CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST))return q;let K={};for(let[_,z]of Object.entries(q))if(!nx4(_))K[_]=z;return K}function JxY(q){if(!q||!rQ8)return q||{};let K={};for(let[_,z]of Object.entries(q))if(!rQ8.has(_))K[_]=z;return K}function rS6(q){return JxY(HxY(jxY(q)))}function jUK(){if(rQ8===void 0)rQ8=process.env.CLAUDE_CODE_ENTRYPOINT==="claude-desktop"?new Set(Object.keys(process.env)):null;Object.assign(process.env,rS6(j8().env));for(let K of MxY){if(K==="policySettings")continue;if(!$J(K))continue;Object.assign(process.env,rS6(v1(K)?.env))}Pm(),Object.assign(process.env,rS6(v1("policySettings")?.env));let q=rS6(Z7()?.env);for(let[K,_]of Object.entries(q))if(iN6.has(K.toUpperCase()))process.env[K]=_}function xd(){Object.assign(process.env,rS6(j8().env)),Object.assign(process.env,rS6(Z7()?.env)),_C7(),rF7(),l1q(),Zj8()}var rQ8,MxY;var q48=y(()=>{lF1();Lp6();V1();m8();lL8();PI();qv();kO();U1();MxY=["userSettings","flagSettings","policySettings"]});import{createServer as XxY}from"node:net";function t_7(q){let K=q.length,_=[],z=K;while(z>127)_.push(z&127|128),z>>>=7;_.push(z);let Y=new Uint8Array(1+_.length+K);return Y[0]=10,Y.set(_,1),Y.set(q,1+_.length),Y}function WxY(q){if(q.length===0)return new Uint8Array(0);if(q[0]!==10)return null;let K=0,_=0,z=1;while(z<q.length){let Y=q[z];if(K|=(Y&127)<<_,z++,(Y&128)===0)break;if(_+=7,_>28)return null}if(z+K>q.length)return null;return q.subarray(z,z+K)}function JUK(){return{connectBuf:Buffer.alloc(0),pending:[],wsOpen:!1,established:!1,closed:!1}}async function MUK(q){let K="Basic "+Buffer.from(`${q.sessionId}:${q.token}`).toString("base64"),_=`Bearer ${q.token}`,z=typeof Bun<"u"?DxY(q.wsUrl,K,_):await fxY(q.wsUrl,K,_);return N(`[upstreamproxy] relay listening on 127.0.0.1:${z.port}`),z}function DxY(q,K,_){let z=Bun.listen({hostname:"127.0.0.1",port:0,socket:{open(Y){Y.data={...JUK(),writeBuf:[]}},data(Y,$){let A=Y.data;XUK({write:(w)=>{let j=typeof w==="string"?Buffer.from(w,"utf8"):w;if(A.writeBuf.length>0){A.writeBuf.push(j);return}let H=Y.write(j);if(H<j.length)A.writeBuf.push(j.subarray(H))},end:()=>Y.end()},A,$,q,K,_)},drain(Y){let $=Y.data;while($.writeBuf.length>0){let A=$.writeBuf[0],O=Y.write(A);if(O<A.length){$.writeBuf[0]=A.subarray(O);return}$.writeBuf.shift()}},close(Y){oS6(Y.data)},error(Y,$){N(`[upstreamproxy] client socket error: ${$.message}`),oS6(Y.data)}}});return{port:z.port,stop:()=>z.stop(!0)}}async function fxY(q,K,_){s_7=(await Promise.resolve().then(() => (W96(),MI6))).default;let z=new WeakMap,Y=XxY(($)=>{let A=JUK();z.set($,A);let O={write:(w)=>{$.write(typeof w==="string"?w:Buffer.from(w))},end:()=>$.end()};$.on("data",(w)=>XUK(O,A,w,q,K,_)),$.on("close",()=>oS6(z.get($))),$.on("error",(w)=>{N(`[upstreamproxy] client socket error: ${w.message}`),oS6(z.get($))})});return new Promise(($,A)=>{Y.once("error",A),Y.listen(0,"127.0.0.1",()=>{let O=Y.address();if(O===null||typeof O==="string"){A(Error("upstreamproxy: server has no TCP address"));return}$({port:O.port,stop:()=>Y.close()})})})}function XUK(q,K,_,z,Y,$){if(!K.ws){K.connectBuf=Buffer.concat([K.connectBuf,_]);let A=K.connectBuf.indexOf(`\r

Callers 2

fsYFunction · 0.80
runFunction · 0.80

Calls 6

createOptionMethod · 0.95
_registerOptionMethod · 0.95
_exitMethod · 0.95
attributeNameMethod · 0.80
onMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected