-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.js
51 lines (42 loc) · 1.52 KB
/
manager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env node
const ipt = require('ipt')
const out = require('simple-output')
const { exec } = require('child_process')
const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
const runGitAccountManager = (gam) => {
process.stdin.on('keypress', (ch, key) => { key && key.name === 'escape' && process.exit(0) })
const DEFAULT = { name: 'Show configuration', value: 'git config --global -l' }
const options = gam.map((el) => ({
name: `Set profile :: <${el.name}>`,
value: `git config --global user.email "${el.email}" && git config --global user.name "${el.name}" && git config --global -l`
}))
out.success('@ Git Account Manager @')
ipt(
[DEFAULT, ...options],
{
message: 'Select Git Account to set as global',
autocomplete: true,
multiple: false,
size: options.length + 1
})
.then(async (command) => { await executeConsoleCommand(command) })
.catch(() => {})
}
const executeConsoleCommand = async command => {
// out.success('launching ' + command)
await exec(`"${command}"`, (error, stdout, stderr) => {
error && console.log(`\n:: ERROR :: \n\n${error.message}`)
stderr && console.log(`\n:: STDERR :: \n\n${stderr}`)
console.log(`\n:: CURRENT GIT GLOBAL CONFIGURATION :: \n\n${stdout}`)
})
}
rl.on('close', () => { console.log('* COMPLETED *') })
;(async () => {
let gam = []
try { gam = require(process.env.HOME + '/.gam.json') } catch (error) {}
runGitAccountManager(gam)
})()