"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.configCmd=void 0;const o=require("../config"),r=e(require("../log")),n=require("../util"),t=require("../config/DefaultConfig"),s=require("../common/Constants"),i=e(require("path")),a=e(require("os")),f=require("../common/message");function c(e){return!e.startsWith("_")&&e!==t.AuthType.READ&&e!==t.AuthType.READ_WRITE}function g(e){if(process.argv.length>4)throw new Error(f.Messages.Config.ListCommandParamError);const r=[];for(const n of o.config.data.keys()){if(n===t.configType.DEFAULT&&!e)continue;const s=o.config.data.get(n);if(!s||s.size<=0)continue;const i=o.config.sources.get(n);r.push(`; "${n}" config from ${i}`,""),s.forEach(((e,t)=>{if(!c(t))return;const s=o.config.find(t);let i="",a="";s&&n!==s&&(i="; ",a=`; overridden by ${s}`),r.push(`${i}${t} = ${JSON.stringify(e)} ${a}`)})),r.push("")}e||r.push(`; "user" config from ${i.default.join(a.default.homedir(),s.Constants.PmDir,s.Constants.PmRc)}`,`; node bin location = ${process.execPath}`,`; node version = ${process.version}`,`; ${s.Constants.PM} local prefix = ${a.default.homedir()}`,`; ${s.Constants.PM} version = ${s.Constants.PmVersion}`,`; cwd = ${process.cwd()}`,`; HOME = ${a.default.homedir()}`),(0,n.output)(r.join("\n").trim())}exports.configCmd=function(e,t,s,i){switch(e){case"set":!function(e,n){if(process.argv.length>6||null==e||null==n)throw new Error(f.Messages.Config.SetCommandParamError);e=e.trim(),n=n.trim(),r.default.debug("config","set {} {}",e,n),o.config.set(e,n),o.config.save()}(t,s);break;case"get":!function(e,r){if(process.argv.length>5)throw new Error(f.Messages.Config.GetCommandParamError);if(e){if(!c(e))throw new Error((0,f.format)(f.Messages.Config.ProtectedKey,{key:e}));{const r=o.config.get(e);(0,n.output)(String(r))}}else g(r)}(t,i.long);break;case"delete":!function(e){if(process.argv.length>5||!e)throw new Error(f.Messages.Config.DeleteCommandParamError);if(!o.config.delete(e))throw new Error((0,f.format)(f.Messages.Config.KeyNotExist,{key:e}));o.config.save()}(t);break;case"list":case"ls":i.json?function(){if(process.argv.length>5)throw new Error(f.Messages.Config.ListCommandParamError);const e={};for(const r of o.config.data.values())for(const n of r.keys())c(n)&&(e[n]=o.config.get(n));(0,n.output)(JSON.stringify(e,null,2))}():g(i.long);break;default:throw e?new Error((0,f.format)(f.Messages.Config.SubcommandNotSupport,{subcommand:e})):new Error(f.Messages.Config.SubcommandIsEmpty)}};