feat: migrate from inquirer to @inquirer/prompts for interactive prompts
- Replaced inquirer with @inquirer/prompts in various command files for improved prompt handling. - Updated confirmation and input prompts in commands such as app, config, deploy, login, and others. - Added a new command 'cc' for switching between Claude code models with appropriate configurations. - Enhanced user experience by ensuring prompts are more streamlined and consistent across the application.
This commit is contained in:
@@ -3,7 +3,7 @@ import { checkFileExists, getConfig, writeConfig } from '@/module/index.ts';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { chalk } from '@/module/chalk.ts';
|
||||
import inquirer from 'inquirer';
|
||||
import { confirm, input } from '@inquirer/prompts';
|
||||
|
||||
// 设置工作目录
|
||||
const setWorkdir = async (options: { workdir: string }) => {
|
||||
@@ -24,15 +24,11 @@ const setWorkdir = async (options: { workdir: string }) => {
|
||||
console.log('路径不存在');
|
||||
fs.mkdirSync(finalPath, { recursive: true });
|
||||
}
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'confirm',
|
||||
message: `Are you sure you want to set the workdir to: ${finalPath}?`,
|
||||
default: false,
|
||||
},
|
||||
]);
|
||||
if (answers.confirm) {
|
||||
const confirmed = await confirm({
|
||||
message: `Are you sure you want to set the workdir to: ${finalPath}?`,
|
||||
default: false,
|
||||
});
|
||||
if (confirmed) {
|
||||
flag = true;
|
||||
config.workdir = finalPath;
|
||||
console.log(chalk.green(`set workdir success:`, finalPath));
|
||||
@@ -81,15 +77,11 @@ const command = new Command('config')
|
||||
console.log('路径不存在');
|
||||
fs.mkdirSync(finalPath, { recursive: true });
|
||||
}
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'confirm',
|
||||
message: `Are you sure you want to set the workdir to: ${finalPath}?`,
|
||||
default: false,
|
||||
},
|
||||
]);
|
||||
if (answers.confirm) {
|
||||
const confirmed = await confirm({
|
||||
message: `Are you sure you want to set the workdir to: ${finalPath}?`,
|
||||
default: false,
|
||||
});
|
||||
if (confirmed) {
|
||||
flag = true;
|
||||
config.workdir = finalPath;
|
||||
console.log(chalk.green(`set workdir success:`, finalPath));
|
||||
@@ -100,15 +92,11 @@ const command = new Command('config')
|
||||
if (options.set) {
|
||||
const key = options.set;
|
||||
let value = options.value;
|
||||
const answer = await inquirer.prompt([
|
||||
{
|
||||
type: 'input',
|
||||
name: 'value',
|
||||
if (!value) {
|
||||
value = await input({
|
||||
message: `Enter your ${key}:(current: ${config[key]})`,
|
||||
when: () => !value,
|
||||
},
|
||||
]);
|
||||
value = answer.value || value;
|
||||
});
|
||||
}
|
||||
if (key && value) {
|
||||
flag = true;
|
||||
config[key] = value;
|
||||
@@ -138,16 +126,10 @@ const setCommand = new Command('set')
|
||||
return;
|
||||
}
|
||||
let flag = false;
|
||||
const answer = await inquirer.prompt([
|
||||
{
|
||||
type: 'input',
|
||||
name: 'value',
|
||||
if (value === 'not_input') {
|
||||
value = await input({
|
||||
message: `Enter your ${key}:(current: ${config[key]})`,
|
||||
when: () => value === 'not_input',
|
||||
},
|
||||
]);
|
||||
if (value === 'not_input' && !answer.value) {
|
||||
value = '';
|
||||
});
|
||||
}
|
||||
if (key === 'workdir') {
|
||||
await setWorkdir({ workdir: value });
|
||||
@@ -192,15 +174,11 @@ const getCommand = new Command('get')
|
||||
.action(async (key) => {
|
||||
const config = getConfig();
|
||||
const keys = Object.keys(config);
|
||||
const answer = await inquirer.prompt([
|
||||
{
|
||||
type: 'input',
|
||||
name: 'key',
|
||||
if (!key) {
|
||||
key = await input({
|
||||
message: `Enter your key:(keys: ${JSON.stringify(keys)})`,
|
||||
when: () => !key,
|
||||
},
|
||||
]);
|
||||
key = answer.key || key;
|
||||
});
|
||||
}
|
||||
|
||||
if (config[key]) {
|
||||
console.log(chalk.green(`get ${key}:`));
|
||||
|
||||
Reference in New Issue
Block a user