diff --git a/package.json b/package.json index e84ac68..b2669a3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/envision-cli", - "version": "0.0.21", + "version": "0.0.22", "description": "envision command tools", "main": "dist/index.js", "type": "module", diff --git a/src/command/login.ts b/src/command/login.ts index b32fa64..c19b803 100644 --- a/src/command/login.ts +++ b/src/command/login.ts @@ -73,8 +73,7 @@ const showMe = async (show = true) => { return me; }; -const switchOrgCommand = new Command('switchOrg').argument('', 'Switch to another organization').action(async (options) => { - // console.log('options', options); +const switchOrgCommand = new Command('switch').argument('', 'Switch to another organization or username').action(async (username) => { const config = getConfig(); if (!config.token) { console.log('Please login first'); @@ -86,42 +85,24 @@ const switchOrgCommand = new Command('switchOrg').argument('', 'Switch return; } const me = meGet.data?.value || {}; - if (me?.username === options) { + if (me?.username === username) { // console.log('Already in', options); - console.log('success switch to', options); + console.log('success switch to', username); return; } - const res = await switchOrg(options); + const res = await switchOrg(username); if (res.code === 200) { const token = res.data.token; writeConfig({ ...config, token }); - console.log('Switch Org Success'); + console.log(`Switch ${username} Success`); await showMe(); } else { - console.log('Switch Org Failed', res.message || ''); + console.log(`Switch ${username} Failed`, res.message || ''); } }); program.addCommand(switchOrgCommand); -const switchMeCommand = new Command('switchMe').action(async () => { - const config = getConfig(); - if (!config.token) { - console.log('Please login first'); - return; - } - const res = await switchMe(); - if (res.code === 200) { - const token = res.data.token; - writeConfig({ ...config, token }); - console.log('Switch Me Success'); - showMe(); - } else { - console.log('Switch Me Failed', res.message || ''); - } -}); -program.addCommand(switchMeCommand); - const command = new Command('me').description('').action(async () => { await showMe(); });