-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhelpers.js
43 lines (39 loc) · 937 Bytes
/
helpers.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
const chalk = require("chalk");
const commands = require("./commands");
/**
* Swap the keys and values of a given object.
*
* @param {object} obj
* @returns {object}
*/
const swap = obj => {
var swapped = {};
for (var key in obj) {
swapped[obj[key]] = key;
}
return swapped;
};
/**
* format the output message.
* @param {string} data
*/
const formatMessage = (cmd, data) => {
let message = chalk.magenta.bold(`mgit \`git ${cmd}\`...`);
return message + `\n\n${chalk.blue(data)}`;
};
/**
* Retrieve the appropriate `git` command from the alias that was passed.
* If it doesn't exist, return the alias itself. Enables backward compatibility.
* @param {string} alias
*/
const gitCommandByAlias = alias => {
let swappedCommands = swap(commands);
return swappedCommands[alias] === undefined
? [alias]
: swappedCommands[alias];
};
module.exports = {
swap,
gitCommandByAlias,
formatMessage
};