feat: login by command by web

This commit is contained in:
2025-02-25 20:04:24 +08:00
parent 02a1f51d63
commit 26c6248d10
8 changed files with 644 additions and 210 deletions

View File

@@ -11,10 +11,11 @@ app.addCommand(token);
const baseURL = new Command('baseURL')
.alias('base')
.alias('registry')
.description('show baseURL')
.option('-a, --add <baseURL>', 'add baseURL')
.option('-r, --remove <number>', 'remove baseURL number')
.option('-s, --set <number>', 'set current baseURL')
.option('-s, --set <number|string>', 'set current baseURL, use number to set from list or string to set')
.option('-l, --list', 'list baseURL')
.option('-c, --clear', 'clear baseURL')
.action(async (opts) => {
@@ -29,7 +30,7 @@ const baseURL = new Command('baseURL')
console.log('expand baseURLList is empty');
return;
}
console.log('----current baseURL:' + config.baseURL+'----\n');
console.log('----current baseURL:' + config.baseURL + '----\n');
list.forEach((item, index) => {
console.log(`${index + 1}: ${item}`);
});
@@ -55,12 +56,25 @@ const baseURL = new Command('baseURL')
return;
}
if (opts.set) {
const index = Number(opts.set) - 1;
if (index < 0 || index >= list.length) {
console.log('index out of range');
const isNumber = !isNaN(Number(opts.set));
if (isNumber) {
const index = Number(opts.set) - 1;
if (index < 0 || index >= list.length) {
console.log('index out of range');
return;
}
writeConfig({ ...config, baseURL: list[index] });
console.log('set baseURL success:', list[index]);
} else {
try {
new URL(opts.set);
} catch (error) {
console.log('invalid baseURL:', opts.set);
return;
}
writeConfig({ ...config, baseURL: opts.set });
console.log('set baseURL success:', opts.set);
}
writeConfig({ ...config, baseURL: list[index] });
console.log('set baseURL success:', list[index]);
return;
}
if (opts.list) {
@@ -75,7 +89,7 @@ const baseURL = new Command('baseURL')
});
app.addCommand(baseURL);
const setBaseURL = new Command('setBaseURL').description('set baseURL').action(async () => {
const setBaseURL = new Command('set').description('set baseURL').action(async () => {
const config = getConfig();
const answers = await inquirer.prompt([
{
@@ -88,7 +102,7 @@ const setBaseURL = new Command('setBaseURL').description('set baseURL').action(a
writeConfig({ ...config, baseURL });
});
app.addCommand(setBaseURL);
baseURL.addCommand(setBaseURL);
// const showQueryURL = new Command('showQueryURL').description('show query URL').action(async () => {
// console.log("url", query.url);