gittttup
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

84 lines
2.7 KiB

#!/usr/bin/env node
const inquirer = require('inquirer');
const program = require('commander');
const util = require('../util')
const git_util = require('../git_util.js');
const prompt = require('../prompt.js');
program
.version(require('../package.json').version, '-v, --version') // 定义版本信息
.usage('<command> [options]'); // 定义命令用法
program
.command('check [options]', {
noHelp: false,
isDefault: true
})
.description('检查状态') // 给rm命令添加描述信息,获取命令帮助信息的时候会显示
.option('--rb', '查看远程分支')
.action(async (options, cmd) => { // 对应命令的处理函数
let currentPath = process.cwd();
let isClean = await util._isClean();
console.log('当前节点是否干净?', isClean);
let branch = await util._getBranch();
console.log('当前所在分支:', branch);
let remote = await util._getAllRemote();
console.log('所有远程源:', remote);
if (cmd.rb) {
console.log('所有分支');
let info = await util.exec('git branch -a');
console.log(info);
}
// let info = await util.exec('git status');
});
program
.command('sync')
.description('提交所有源')
.action(async (options, cmd) => { // 对应命令的处理函数
// let currentPath = process.cwd();
let remote = await util._getAllRemote();
let branch = await util._getBranch();; //当前分支
if (remote.length > 0) {
let isPushAll = await prompt.isPushAll();
if (isPushAll) {
let pushMsg = await prompt.pushMsg();
for (let i = 0; i < remote.length; i++) {
const o = remote[i];
let isclean = await util._isClean();
if (!isclean) {
await git_util.all(pushMsg, o, branch);
} else {
await git_util.push(o, branch);
}
}
} else {
let list = await prompt.listPush(remote);
if (list.length) {
let pushMsg = await prompt.pushMsg();
for (let i = 0; i < list.length; i++) {
const o = list[i];
let isclean = await util._isClean();
if (!isclean) {
await git_util.all(pushMsg, o, branch);
} else {
await git_util.push(o, branch);
}
}
} else {
console.log('您未选择源进行提交');
}
}
} else {
console.log('请添加源');
// let {
// name,
// url
// } = await prompt.addRemote();
// await util.exec('git remote add ' + name + ' ' + url);
// console.log('添加成功');
}
// let info = await util.exec('git status');
});
program.parse(process.argv); // commander的入口欧,传入命令行参数执行解析