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

Commit b639633

Browse files
authored
Fix #3 #4 Add Version Check and Update Readme (#5)
Fix #3 #4 Add Version Check and Update Readme
2 parents f90c835 + dc6eff5 commit b639633

File tree

4 files changed

+202
-13
lines changed

4 files changed

+202
-13
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<a href="https://travis-ci.org/excalith/git-cheats-cli">
1313
<img alt="Build Status" height="18" src="https://img.shields.io/travis/excalith/git-cheats-cli.svg">
1414
</a>
15+
<a href="https://www.npmjs.com/package/git-commands-cli">
16+
<img alt="NPM Installs" height="18" src="https://img.shields.io/npm/dt/git-commands-cli.svg?label=installs">
17+
</a>
1518
<a href="https://github.com/excalith/Git-Cheats-Cli/issues">
1619
<img alt="Build Status" height="18" src="https://img.shields.io/github/issues/excalith/Git-Cheats-Cli.svg">
1720
</a>
@@ -34,14 +37,16 @@ You can either use web based [GitCheats App](http://gitcheats.com) from your bro
3437

3538
## How To Install:
3639

37-
- Requirements
38-
- [NodeJS](https://nodejs.org)
39-
- [NPM](https://www.npmjs.com/get-npm)
40+
### Using NPM
41+
42+
`npm i -g git-commands-cli`
43+
44+
### Clone
45+
4046
- Clone or Download this repository
4147
- Within the directory, from your favorite terminal
4248
- npm install
4349
- npm link (might ask for permission depending on your OS)
44-
- Now you can use gitcheats directly from your terminal!
4550

4651
## Available Commands:
4752

@@ -51,6 +56,7 @@ You can either use web based [GitCheats App](http://gitcheats.com) from your bro
5156
| gitcheats [command] | Print command descriptions right into your terminal |
5257
| gitcheats --open [command] | Open gitcheats.com in browser with your command filtered |
5358
| gitcheats --language [key] | Set your preffered language (Default: en) |
59+
| gitcheats --version | Shows and checks version |
5460
| gitcheats --help | Show commands for the app |
5561

5662
## How To Contribute:

cli.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ const Configstore = require("configstore");
77
const pkg = require("./package.json");
88
const jsonLink =
99
"https://raw.githubusercontent.com/excalith/git-cheats/master/assets/commands.json";
10+
const boxen = require("boxen");
11+
const checkForUpdate = require("update-check");
1012
const conf = new Configstore(pkg.name, { lang: "en" });
1113

1214
let cmd = process.argv[2];
1315
let bar = chalk.green("║ ");
1416
let lang = conf.get("lang");
1517

1618
// Check Arguments
17-
if (cmd == "-h" || cmd == "--help") {
19+
if (cmd === "-v" || cmd === "--version") {
20+
ShowVersion();
21+
} else if (cmd == "-h" || cmd == "--help") {
1822
ShowHelp();
1923
} else if (cmd == "-o" || cmd == "--open") {
2024
LaunchBrowser(process.argv[3]);
@@ -26,6 +30,41 @@ if (cmd == "-h" || cmd == "--help") {
2630
LaunchBrowser(false);
2731
}
2832

33+
//** Check Updates */
34+
async function ShowVersion() {
35+
let update = null;
36+
37+
try {
38+
update = await checkForUpdate(pkg);
39+
} catch (error) {
40+
console.log(chalk.red("\nFailed to check for updates:"));
41+
console.error(error);
42+
}
43+
44+
let updateText;
45+
let commandText;
46+
47+
if (update) {
48+
updateText =
49+
"Update available " +
50+
chalk.gray(pkg.version) +
51+
" → " +
52+
chalk.green(update.latest);
53+
commandText = "Run " + chalk.cyan("npm i -g " + pkg.name) + " to update";
54+
} else {
55+
updateText = "You are using the latest version";
56+
commandText = pkg.name + " v" + pkg.version;
57+
}
58+
59+
console.log(
60+
boxen(updateText + "\n" + commandText, {
61+
padding: 1,
62+
margin: 1,
63+
align: "center"
64+
})
65+
);
66+
}
67+
2968
/**
3069
* Shows CLI help
3170
*/

package-lock.json

Lines changed: 148 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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "git-commands-cli",
3-
"version": "1.3.3",
3+
"version": "1.3.4",
44
"description": "A Companion CLI App For Gitcheats",
55
"main": "cli.js",
66
"scripts": {
@@ -17,11 +17,13 @@
1717
"author": "Can Cellek",
1818
"license": "MIT",
1919
"dependencies": {
20+
"boxen": "^4.1.0",
2021
"chalk": "^2.4.2",
2122
"configstore": "^5.0.0",
2223
"opn": "^6.0.0",
2324
"ora": "^4.0.2",
24-
"request": "^2.88.0"
25+
"request": "^2.88.0",
26+
"update-check": "^1.5.3"
2527
},
2628
"repository": {
2729
"type": "git",

0 commit comments

Comments
 (0)