@vtian/git-branch-clear
Advanced tools
+66
-14
| #!/usr/bin/env node | ||
| const { program } = require('commander') | ||
| const pkg = require('../package.json') | ||
| const chalk = require('chalk') | ||
| const execa = require('execa') | ||
| const pkg = require('../package.json') | ||
| const gbc = require('../lib/git-branch-clear') | ||
@@ -18,8 +19,59 @@ // 用户本地是否安装了git程序 | ||
| checkGit() | ||
| program | ||
| .version(`gitb ${pkg.version}`, '-v, --version', '查看当前版本号') | ||
| .usage('[options]') | ||
| .usage('<command> [options]') | ||
| .helpOption('-h, --help', '查看帮助信息') | ||
| program | ||
| .command('delete') | ||
| .alias('d') | ||
| .description('选择需要删除的分支') | ||
| .action(() => { | ||
| gbc.gitDeleteAllBranch() | ||
| }) | ||
| program | ||
| .command('delete-local <branchName>') | ||
| .alias('dl') | ||
| .description('删除指定的本地分支') | ||
| .action((branchName) => { | ||
| gbc.gitDeleteLocalBranch(branchName) | ||
| }) | ||
| program | ||
| .command('delete-remote <branchName>') | ||
| .alias('dr') | ||
| .description('删除指定的远程分支') | ||
| .action((branchName) => { | ||
| gbc.gitDeleteRemoteBranch(branchName) | ||
| }) | ||
| program | ||
| .command('list') | ||
| .alias('l') | ||
| .description('查看所有分支列表') | ||
| .action(() => { | ||
| gbc.gitShowAllBranchList(true) | ||
| }) | ||
| program | ||
| .command('list-local') | ||
| .alias('ll') | ||
| .description('查看本地分支列表') | ||
| .action(() => { | ||
| gbc.gitShowLocalBranchList() | ||
| }) | ||
| program | ||
| .command('list-remote') | ||
| .alias('lr') | ||
| .description('查看远程分支列表') | ||
| .action(() => { | ||
| gbc.gitShowRemoteBranchList() | ||
| }) | ||
| program.on('command:*', ([cmd]) => { | ||
| program.outputHelp() | ||
| console.log() | ||
| console.log(` ` + chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)) | ||
@@ -30,15 +82,15 @@ console.log() | ||
| program | ||
| .description(chalk.yellow('Tips: 更加方便的删除分支,支持批量删除')) | ||
| .option('-d, --delete <branchName>', '快速删除指定的本地分支') | ||
| .option('-dr, --delete-remote <branchName>', '快速删除指定的远程分支') | ||
| .option('-da, --delete-all', '选择需要删除的分支') | ||
| .option('-l, --list', '查看本地分支列表') | ||
| .option('-lr, --list-remote', '查看远程分支列表') | ||
| .option('-la, --list-all', '查看所有分支列表') | ||
| .action((options, command) => { | ||
| require('../lib/git-branch-clear.js')(options, command) | ||
| }) | ||
| .helpOption('-h, --help', '查看帮助信息') | ||
| // program | ||
| // .description(chalk.yellow('Tips: 更加方便的删除分支,支持批量删除')) | ||
| // .option('-d, --delete <branchName>', '快速删除指定的本地分支') | ||
| // .option('-dr, --delete-remote <branchName>', '快速删除指定的远程分支') | ||
| // .option('-da, --delete-all', '选择需要删除的分支') | ||
| // .option('-l, --list', '查看本地分支列表') | ||
| // .option('-lr, --list-remote', '查看远程分支列表') | ||
| // .option('-la, --list-all', '查看所有分支列表') | ||
| // .action((options, command) => { | ||
| // // require('../lib/git-branch-clear.js')(options, command) | ||
| // }) | ||
| // .helpOption('-h, --help', '查看帮助信息') | ||
| program.parse(process.argv) |
+33
-24
@@ -8,26 +8,35 @@ 'use strict' | ||
| module.exports = function (options, command) { | ||
| // log('options:', options) | ||
| // log('command:', command) | ||
| if (options.delete) { | ||
| // 删除指定的本地分支 | ||
| gitDeleteLocalBranch(options.delete) | ||
| } else if (options.deleteRemote) { | ||
| // 删除指定的远程分支 | ||
| gitDeleteRemoteBranch(options.deleteRemote) | ||
| } else if (options.deleteAll) { | ||
| // 选择删除的分支 | ||
| gitDeleteAllBranch() | ||
| } else if (options.list) { | ||
| // 列出本地分支 | ||
| gitShowLocalBranchList() | ||
| } else if (options.listRemote) { | ||
| // 列出远程分支 | ||
| gitShowRemoteBranchList() | ||
| } else if (options.listAll) { | ||
| // 列出所有分支 | ||
| gitShowAllBranchList(true) | ||
| } else { | ||
| program.outputHelp() | ||
| } | ||
| // module.exports = function (options, command) { | ||
| // // log('options:', options) | ||
| // // log('command:', command) | ||
| // if (options.delete) { | ||
| // // 删除指定的本地分支 | ||
| // gitDeleteLocalBranch(options.delete) | ||
| // } else if (options.deleteRemote) { | ||
| // // 删除指定的远程分支 | ||
| // gitDeleteRemoteBranch(options.deleteRemote) | ||
| // } else if (options.deleteAll) { | ||
| // // 选择删除的分支 | ||
| // gitDeleteAllBranch() | ||
| // } else if (options.list) { | ||
| // // 列出本地分支 | ||
| // gitShowLocalBranchList() | ||
| // } else if (options.listRemote) { | ||
| // // 列出远程分支 | ||
| // gitShowRemoteBranchList() | ||
| // } else if (options.listAll) { | ||
| // // 列出所有分支 | ||
| // gitShowAllBranchList(true) | ||
| // } else { | ||
| // program.outputHelp() | ||
| // } | ||
| // } | ||
| module.exports = { | ||
| gitDeleteLocalBranch, | ||
| gitDeleteRemoteBranch, | ||
| gitDeleteAllBranch, | ||
| gitShowLocalBranchList, | ||
| gitShowRemoteBranchList, | ||
| gitShowAllBranchList | ||
| } | ||
@@ -34,0 +43,0 @@ |
+1
-1
@@ -34,3 +34,3 @@ { | ||
| }, | ||
| "version": "0.0.4" | ||
| "version": "0.0.5" | ||
| } |
+6
-6
@@ -21,9 +21,9 @@ # `@vtian/git-branch-clear` | ||
| gitb -l # 本地分支列表 | ||
| gitb -lr # 远程分支列表 | ||
| gitb -la # 所有分支列表 | ||
| gitb l # 查看所有分支列表 | ||
| gitb ll # 查看本地分支列表 | ||
| gitb lr # 查看远程分支列表 | ||
| gitb -d <branchName> # 删除指定的本地分支 | ||
| gitb -dr <branchName> # 删除指定的远程分支 | ||
| gitb -da # 批量删除分支 | ||
| gitb d # 选择批量删除分支 | ||
| gitb dl <branchName> # 删除指定的本地分支 | ||
| gitb dr <branchName> # 删除指定的远程分支 | ||
| ``` |
7830
21.77%226
30.64%