Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

Commit a9c289b

Browse files
committed
Remove Table For Tiny Terminals
1 parent 1d0eac5 commit a9c289b

File tree

2 files changed

+54
-38
lines changed

2 files changed

+54
-38
lines changed

cli.js

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,92 @@
11
#!/usr/bin/env node
22
const chalk = require('chalk');
3-
const Table = require('cli-table');
43
const getJSON = require('get-json')
54
const opn = require('opn');
65
const ora = require('ora')
76

7+
const jsonLink = "https://raw.githubusercontent.com/excalith/Git-Cheats/master/assets/commands.json";
88
let cmd = process.argv[2];
9+
let bar = chalk.green("║ ");
910

10-
11+
// Check Arguments
1112
if (cmd == "-h" || cmd == "--help") {
1213
ShowHelp();
1314
}
1415
else if (cmd == "-l" || cmd == "--launch") {
15-
opn("www.gitcheats.com?c=" + process.argv[3])
16+
LaunchBrowser(process.argv[3]);
1617
}
1718
else if (cmd) {
18-
GetCommand(process.argv[2])
19+
FetchCommand(process.argv[2])
1920
}
2021
else {
21-
opn("www.gitcheats.com")
22+
LaunchBrowser(false);
2223
}
2324

25+
/**
26+
* Shows CLI help
27+
*/
2428
function ShowHelp() {
2529
console.log("");
2630
console.log("A Terminal App For Reaching Gitcheats.com Easily");
2731
console.log("");
2832
console.log("Commands:");
29-
console.log("gitcheats " + chalk.blue("[command]") + " Print command descriptions right into your terminal");
30-
console.log("gitcheats " + chalk.green("-l --launch") + chalk.blue(" [command]") + " Launch GitCheats.com in browser with your command filtered");
33+
console.log("gitcheats " + chalk.yellow("[command]") + " Print command descriptions right into your terminal");
34+
console.log("gitcheats " + chalk.green("-l --launch") + chalk.yellow(" [command]") + " Launch GitCheats.com in browser with your command filtered");
3135
console.log("gitcheats " + chalk.green("-h --help") + " Display this help");
3236
}
3337

34-
function GetCommand(cmd) {
35-
console.log("\n");
36-
const spinner = ora().start();
37-
spinner.color = 'blue';
38-
spinner.text = chalk.blue("Fetching '" + chalk.green(cmd) + "' from gitcheats.com");
38+
/**
39+
* Fetch command from original gitcheats json
40+
*
41+
* @param {String} cmd Command to search for within json file
42+
*/
43+
function FetchCommand(cmd) {
44+
const spinner = ora({
45+
text: chalk.bold("Fetching '" + chalk.yellow(cmd) + "' from gitcheats.com"),
46+
color: 'green',
47+
interval: 80,
48+
spinner: "dots"
49+
}).start();
3950

40-
getJSON('https://raw.githubusercontent.com/excalith/Git-Cheats/master/assets/commands.json', function (error, json) {
51+
getJSON(jsonLink, function (error, json) {
4152
let data = json.commands[cmd];
42-
console.log("\n\n");
53+
console.log("\n");
4354

4455
if (data == null) {
45-
console.log("Command " + chalk.red(cmd) + " not found in gitcheats.com");
46-
console.log(chalk.gray("Please consider contributing " + "https://github.com/excalith/Git-Cheats"))
56+
spinner.fail("Command '" + chalk.red(cmd) + "' not found in gitcheats.com");
57+
console.log(chalk.gray("Please consider contributing https://github.com/excalith/Git-Cheats"))
4758
}
4859
else {
49-
var table = new Table({
50-
head: [chalk.green.bold('Option'), chalk.green.bold('Description')],
51-
colWidths: [60, 220],
52-
chars: {
53-
'top': '═', 'top-mid': '╤', 'top-left': '╔', 'top-right': '╗',
54-
'bottom': '═', 'bottom-mid': '╧', 'bottom-left': '╚',
55-
'bottom-right': '╝', 'left': '║', 'left-mid': '╟', 'mid': '─',
56-
'mid-mid': '┼', 'right': '║', 'right-mid': '╢', 'middle': '│'
57-
}
58-
});
59-
60-
table.push(
61-
[cmd, data.desc.en]
62-
);
60+
LogCommand(cmd, data.desc.en);
6361

6462
data.options.forEach(element => {
65-
table.push(
66-
[element.code, element.desc.en]
67-
);
63+
LogCommand(element.code, element.desc.en);
6864
});
69-
70-
console.log(table.toString());
7165
}
72-
7366
spinner.stop();
7467
})
68+
}
69+
70+
/**
71+
* Print command and description into terminal
72+
*
73+
* @param {String} command Command title
74+
* @param {String} description Command description
75+
*/
76+
function LogCommand(command, description) {
77+
console.log(bar + chalk.green.bold("> git " + command));
78+
console.log(bar + description);
79+
console.log(bar);
80+
}
81+
82+
/**
83+
* Fetch command from original gitcheats json
84+
*
85+
* @param {boolean} hasCommand Checks if argv has a git command
86+
*/
87+
function LaunchBrowser(hasCommand) {
88+
if (hasCommand)
89+
opn("www.gitcheats.com?c=" + process.argv[3])
90+
else
91+
opn("www.gitcheats.com")
7592
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "git-cheats-cli",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "A Companion CLI App For Gitcheats",
55
"main": "cli.js",
66
"scripts": {
@@ -10,7 +10,6 @@
1010
"license": "MIT",
1111
"dependencies": {
1212
"chalk": "^2.4.1",
13-
"cli-table": "^0.3.1",
1413
"get-json": "^1.0.0",
1514
"opn": "^5.3.0",
1615
"ora": "^2.1.0"

0 commit comments

Comments
 (0)