fix bugs and change version
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { app, program, Command } from '@/app.ts';
|
||||
import { getConfig, writeConfig } from '@/module/get-config.ts';
|
||||
import { queryLogin, queryMe } from '@/route/index.ts';
|
||||
import { queryLogin, queryMe, switchOrg, switchMe } from '@/route/index.ts';
|
||||
import inquirer from 'inquirer';
|
||||
|
||||
// 导入 login 命令
|
||||
@@ -57,3 +57,50 @@ const loginCommand = new Command('login')
|
||||
});
|
||||
|
||||
app.addCommand(loginCommand);
|
||||
|
||||
const showMe = async () => {
|
||||
const me = await queryMe();
|
||||
if (me.code === 200) {
|
||||
console.log('Me', me.data);
|
||||
} else {
|
||||
console.log('Me failed', me.message);
|
||||
}
|
||||
};
|
||||
|
||||
const switchOrgCommand = new Command('switchOrg').argument('<username>', 'Switch to another organization').action(async (options) => {
|
||||
// console.log('options', options);
|
||||
const config = getConfig();
|
||||
if (!config.token) {
|
||||
console.log('Please login first');
|
||||
return;
|
||||
}
|
||||
const res = await switchOrg(options);
|
||||
if (res.code === 200) {
|
||||
const token = res.data.token;
|
||||
writeConfig({ ...config, token });
|
||||
console.log('Switch Org Success');
|
||||
showMe();
|
||||
} else {
|
||||
console.log('Switch Org Failed', res.message || '');
|
||||
}
|
||||
});
|
||||
|
||||
app.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 || '');
|
||||
}
|
||||
});
|
||||
app.addCommand(switchMeCommand);
|
||||
|
||||
Reference in New Issue
Block a user