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

Commit 31fa17c

Browse files
committed
Add support for fetching data in different languages
1 parent fc1b985 commit 31fa17c

File tree

5 files changed

+146
-19
lines changed

5 files changed

+146
-19
lines changed

.npmignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package
2+
3+
#tests
4+
test
5+
coverage
6+
7+
#build tools
8+
.travis.yml
9+
.jenkins.yml
10+
.codeclimate.yml
11+
12+
#linters
13+
.jscsrc
14+
.jshintrc
15+
.eslintrc*
16+
17+
#editor settings
18+
.idea
19+
.editorconfig

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ You can either use web based [GitCheats App](http://gitcheats.com) from your bro
4545

4646
## Available Commands:
4747

48-
| _Command_ | _Description_ |
49-
| ---------------------------- | ---------------------------------------------------------- |
50-
| gitcheats | Launch gitcheats.com directly |
51-
| gitcheats [command] | Print command descriptions right into your terminal |
52-
| gitcheats --launch [command] | Launch gitcheats.com in browser with your command filtered |
53-
| gitcheats --help | Show commands for the app |
48+
| _Command_ | _Description_ |
49+
| -------------------------- | --------------------------------------------------------- |
50+
| gitcheats | Launch gitcheats.com directly |
51+
| gitcheats [command] | Print command descriptions right into your terminal |
52+
| gitcheats --open [command] | Open gitcheats.com in browser with your command filtered |
53+
| gitcheats --language [key] | Set your preffered language (Keys: en, tr, tel, hin, kli) |
54+
| gitcheats --help | Show commands for the app |
5455

5556
## How To Contribute:
5657

cli.js

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@ const chalk = require("chalk");
33
const getJSON = require("get-json");
44
const opn = require("opn");
55
const ora = require("ora");
6-
6+
const Configstore = require("configstore");
7+
const pkg = require("./package.json");
78
const jsonLink =
89
"https://raw.githubusercontent.com/excalith/Git-Cheats/master/assets/commands.json";
10+
const conf = new Configstore(pkg.name, { lang: "en" });
11+
912
let cmd = process.argv[2];
1013
let bar = chalk.green("║ ");
14+
let lang = conf.get("lang");
1115

1216
// Check Arguments
1317
if (cmd == "-h" || cmd == "--help") {
1418
ShowHelp();
15-
} else if (cmd == "-l" || cmd == "--launch") {
19+
} else if (cmd == "-o" || cmd == "--open") {
1620
LaunchBrowser(process.argv[3]);
21+
} else if (cmd == "-l" || cmd == "--language") {
22+
SetLanguage(process.argv[3]);
1723
} else if (cmd) {
1824
FetchCommand(process.argv[2]);
1925
} else {
@@ -36,10 +42,16 @@ function ShowHelp() {
3642
);
3743
console.log(
3844
"gitcheats " +
39-
chalk.green("-l --launch") +
40-
chalk.yellow(" [command]").padEnd(28) +
45+
chalk.green("-o --open") +
46+
chalk.yellow(" [command]").padEnd(30) +
4147
"Launch gitcheats.com in browser with your command filtered"
4248
);
49+
console.log(
50+
"gitcheats " +
51+
chalk.green("-l --language") +
52+
chalk.yellow(" [key]").padEnd(26) +
53+
"Set your preffered language (Options: en, tr, tel, hin, kli)"
54+
);
4355
console.log(
4456
"gitcheats " + chalk.green("-h --help").padEnd(39) + "Display this help"
4557
);
@@ -75,17 +87,50 @@ function FetchCommand(cmd) {
7587
)
7688
);
7789
} else {
78-
LogCommand(cmd, data.desc.en);
90+
LogCommand(cmd, data.desc[lang]);
7991

8092
data.options.forEach(element => {
81-
LogCommand(element.code, element.desc.en);
93+
LogCommand(element.code, element.desc[lang]);
8294
});
8395
}
8496

8597
spinner.stop();
8698
});
8799
}
88100

101+
/**
102+
* Check if language exists and set it to given key
103+
*
104+
* @param {String} key Language key
105+
*/
106+
function SetLanguage(key) {
107+
const spinner = ora({
108+
text: chalk.white.bold("Fetching Language: " + key),
109+
color: "green",
110+
interval: 80,
111+
spinner: "dots"
112+
}).start();
113+
114+
getJSON(jsonLink, function(error, json) {
115+
let data = json.settings.languages[key];
116+
console.log("\n");
117+
118+
if (data == null) {
119+
spinner.fail("Language not found!");
120+
spinner.info(
121+
chalk.gray(
122+
"Please add your language by contributing to https://github.com/excalith/Git-Cheats"
123+
)
124+
);
125+
} else {
126+
conf.set("lang", key);
127+
spinner.succeed("Language set to " + data + "\n");
128+
}
129+
130+
spinner.stop();
131+
});
132+
}
133+
89134
/**
90135
* Print command and description into terminal
91136
*

package-lock.json

Lines changed: 67 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "git-cheats-cli",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "A Companion CLI App For Gitcheats",
55
"main": "cli.js",
66
"scripts": {
@@ -18,6 +18,7 @@
1818
"license": "MIT",
1919
"dependencies": {
2020
"chalk": "^2.4.1",
21+
"configstore": "^3.1.2",
2122
"get-json": "^1.0.0",
2223
"opn": "^5.3.0",
2324
"ora": "^2.1.0"

0 commit comments

Comments
 (0)