fix: remove switchMe and switchOrg only use switch

This commit is contained in:
熊潇 2025-02-23 13:03:04 +08:00
parent f42e1c8f24
commit 02a1f51d63
2 changed files with 7 additions and 26 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@kevisual/envision-cli", "name": "@kevisual/envision-cli",
"version": "0.0.21", "version": "0.0.22",
"description": "envision command tools", "description": "envision command tools",
"main": "dist/index.js", "main": "dist/index.js",
"type": "module", "type": "module",

View File

@ -73,8 +73,7 @@ const showMe = async (show = true) => {
return me; return me;
}; };
const switchOrgCommand = new Command('switchOrg').argument('<username>', 'Switch to another organization').action(async (options) => { const switchOrgCommand = new Command('switch').argument('<username>', 'Switch to another organization or username').action(async (username) => {
// console.log('options', options);
const config = getConfig(); const config = getConfig();
if (!config.token) { if (!config.token) {
console.log('Please login first'); console.log('Please login first');
@ -86,42 +85,24 @@ const switchOrgCommand = new Command('switchOrg').argument('<username>', 'Switch
return; return;
} }
const me = meGet.data?.value || {}; const me = meGet.data?.value || {};
if (me?.username === options) { if (me?.username === username) {
// console.log('Already in', options); // console.log('Already in', options);
console.log('success switch to', options); console.log('success switch to', username);
return; return;
} }
const res = await switchOrg(options); const res = await switchOrg(username);
if (res.code === 200) { if (res.code === 200) {
const token = res.data.token; const token = res.data.token;
writeConfig({ ...config, token }); writeConfig({ ...config, token });
console.log('Switch Org Success'); console.log(`Switch ${username} Success`);
await showMe(); await showMe();
} else { } else {
console.log('Switch Org Failed', res.message || ''); console.log(`Switch ${username} Failed`, res.message || '');
} }
}); });
program.addCommand(switchOrgCommand); 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 () => { const command = new Command('me').description('').action(async () => {
await showMe(); await showMe();
}); });