@@ -3,17 +3,23 @@ const chalk = require("chalk");
33const getJSON = require ( "get-json" ) ;
44const opn = require ( "opn" ) ;
55const ora = require ( "ora" ) ;
6-
6+ const Configstore = require ( "configstore" ) ;
7+ const pkg = require ( "./package.json" ) ;
78const jsonLink =
89 "https://raw.githubusercontent.com/excalith/Git-Cheats/master/assets/commands.json" ;
10+ const conf = new Configstore ( pkg . name , { lang : "en" } ) ;
11+
912let cmd = process . argv [ 2 ] ;
1013let bar = chalk . green ( "║ " ) ;
14+ let lang = conf . get ( "lang" ) ;
1115
1216// Check Arguments
1317if ( 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 *
0 commit comments