add base url list

This commit is contained in:
2025-02-21 00:47:36 +08:00
parent ce84ab4902
commit 5a691bc350
3 changed files with 86 additions and 23 deletions

View File

@@ -9,10 +9,70 @@ const token = new Command('token').description('show token').action(async () =>
app.addCommand(token);
const baseURL = new Command('baseURL').description('show baseURL').action(async () => {
const config = getConfig();
console.log('baseURL', config.baseURL);
});
const baseURL = new Command('baseURL')
.alias('base')
.description('show baseURL')
.option('-a, --add <baseURL>', 'add baseURL')
.option('-r, --remove <number>', 'remove baseURL number')
.option('-s, --set <number>', 'set current baseURL')
.option('-l, --list', 'list baseURL')
.option('-c, --clear', 'clear baseURL')
.action(async (opts) => {
const config = getConfig();
let list = config.baseURLList || [];
const quineList = (list: string[]) => {
const newList = new Set(list);
return Array.from(newList);
};
const showList = (list: string[]) => {
if (list.length === 0) {
console.log('expand baseURLList is empty');
return;
}
console.log('----current baseURL:' + config.baseURL+'----\n');
list.forEach((item, index) => {
console.log(`${index + 1}: ${item}`);
});
};
if (opts.add) {
list.push(opts.add);
list = quineList(list);
console.log('add baseURL success\n');
writeConfig({ ...config, baseURLList: list });
showList(list);
return;
}
if (opts.remove) {
const index = Number(opts.remove) - 1;
if (index < 0 || index >= list.length) {
console.log('index out of range');
return;
}
list.splice(index, 1);
list = quineList(list);
showList(list);
writeConfig({ ...config, baseURLList: list });
return;
}
if (opts.set) {
const index = Number(opts.set) - 1;
if (index < 0 || index >= list.length) {
console.log('index out of range');
}
writeConfig({ ...config, baseURL: list[index] });
console.log('set baseURL success:', list[index]);
return;
}
if (opts.list) {
showList(list);
return;
}
if (opts.clear) {
writeConfig({ ...config, baseURLList: [] });
return;
}
console.log('current baseURL:', config.baseURL);
});
app.addCommand(baseURL);
const setBaseURL = new Command('setBaseURL').description('set baseURL').action(async () => {