Skip to content

Commit

Permalink
feat: set-git 命令
Browse files Browse the repository at this point in the history
  • Loading branch information
StreakingMan committed Feb 22, 2022
1 parent c1d8415 commit c8d975e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## StreakingMan Cli

### 查看git当前配置名称和邮箱
### 查看当前仓库git配置名称和邮箱
```
skm check-git
```

## 配置当前仓库git配置用户名和邮箱
```
skm set-git
```
29 changes: 29 additions & 0 deletions actions/set-git.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const {execSync} = require('child_process')
const inquirer = require('inquirer')
const setGit = async () => {
const name = await inquirer.prompt([
{
type: 'input',
name: 'name',
message: 'user.name',
default: 'streakingman',
},
])
const email = await inquirer.prompt([
{
type: 'input',
name: 'email',
message: 'user.email',
default: '[email protected]',
},
])
execSync(`git config user.name ${name}`)
execSync(`git config user.email ${email}`)
console.log('设置完成,当前配置:\n')
console.log(`git config user.name ${execSync('git config user.name')}`.trim())
console.log(`git config user.email ${execSync('git config user.email')}`)
}

module.exports = {
setGit
}
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
const {checkGit} = require('./actions/check-git');
const {setGit} = require('./actions/set-git');
const {program} = require('commander');
const fs = require('fs')
const path = require('path')
Expand All @@ -13,8 +14,11 @@ program.version(`${CLINAME}@${version}`, '-v')
.name(CLINAME)

program.command('check-git')
.description('查看当前git配置用户名和邮箱')
.description('查看当前仓库git配置用户名和邮箱')
.action(checkGit)
program.command('set-git')
.description('配置当前仓库git配置用户名和邮箱')
.action(setGit)

program.showHelpAfterError(`${CLINAME} -h 查看帮助`)
program.addHelpCommand(false)
Expand Down

0 comments on commit c8d975e

Please sign in to comment.