@harryisfish/gitt
Version:
这是一个命令行工具,用于帮助你管理 Git 仓库与远端仓库,如保持同步、推送、拉取等。
57 lines (56 loc) • 1.54 kB
JavaScript
import { select, confirm } from '@inquirer/prompts';
import { theme } from './theme';
// 菜单选项
const menuChoices = [
{
name: '清理远程已删除的分支',
value: 'clean',
description: '清理那些在远程仓库已经被删除的本地分支'
},
{
name: '退出',
value: 'exit',
description: '退出程序'
}
];
// 显示主菜单
export async function showMainMenu() {
try {
const options = {
message: '请选择要执行的操作:',
choices: menuChoices,
pageSize: 10, // 一次显示的选项数量
loop: true, // 循环滚动
theme, // 使用自定义主题
};
return await select(options);
}
catch (error) {
return 'exit';
}
}
// 确认提示
export async function confirmAction(message) {
try {
const options = {
message,
default: true,
theme, // 使用自定义主题
};
return await confirm(options);
}
catch (error) {
return false;
}
}
// 初始化 Git 仓库确认
export async function confirmInitRepo() {
return await confirmAction('当前目录不是 Git 仓库,是否要创建?');
}
// 删除分支确认
export async function confirmDeleteBranches(branches) {
if (branches.length === 0)
return false;
const branchList = branches.join('\n - ');
return await confirmAction(`是否删除以下分支?\n - ${branchList}`);
}