Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a7d353b

Browse files
committed
feat: support postgresql as a new language id and some other adjustments
1 parent df69a65 commit a7d353b

File tree

8 files changed

+4449
-2865
lines changed

8 files changed

+4449
-2865
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"editor.formatOnSave": false
3+
}

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
# leetcode-cli
88

9+
> [!NOTE]
10+
> 07/07/2024 - I made the following modification to this cli:
11+
> - Support postgresql as a new language id
12+
> - Use a customized home directory for this tool (i.e. `~/.lc-customized` instead of `~/.lc`) to avoid causing any overlap between my vscode leetcode extension and this tool
13+
> - When showing a problem, by default the problem will be saved at path ./{problem-id}-{dash-separated-problem-name}/{langId}/{dash-separated question-name}.{ext}
14+
915
> Note: This repository is forked from [leetcode-cli](https://github.com/skygragon/leetcode-cli) for temporary usage.
1016
> Note: Copy cookie from webbrowser and Using **leetcode user -c** can temporary fix can't [login problem](https://github.com/jdneo/vscode-leetcode/issues/478).
1117

docs/commands.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ Display question details. With `-g`/`-l`/`-x`, the code template would be auto g
236236
* java
237237
* javascript
238238
* mysql
239+
* postgresql
239240
* php
240241
* python
241242
* python3

lib/commands/show.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
var util = require('util');
3+
const fs = require('fs');
34

45
var _ = require('underscore');
56
var childProcess = require('child_process');
@@ -86,9 +87,14 @@ function genFileName(problem, opts) {
8687
h.langToExt(opts.lang)
8788
];
8889

90+
// save the file in the following directory ./{fid}-{slug}/{opts.lang}
91+
const outputDir = path.join(opts.outdir, file.fmt(config.file.outputDir, problem), h.langToExt(opts.lang).slice(1))
92+
if (!fs.existsSync(outputDir))
93+
fs.mkdirSync(outputDir, { "recursive": true });
94+
8995
// try new name to avoid overwrite by mistake
9096
for (let i = 0; ; ++i) {
91-
const name = path.join(opts.outdir, params.join('.').replace(/\.+/g, '.'));
97+
const name = path.join(outputDir, params.join('.').replace(/\.+/g, '.'));
9298
if (!file.exist(name))
9399
return name;
94100
params[1] = i;

lib/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const DEFAULT_CONFIG = {
2323
'javascript',
2424
'kotlin',
2525
'mysql',
26+
'postgresql',
2627
'php',
2728
'python',
2829
'python3',
@@ -76,6 +77,7 @@ const DEFAULT_CONFIG = {
7677
},
7778
file: {
7879
show: '${fid}.${slug}',
80+
outputDir: '${fid}-${slug}',
7981
submission: '${fid}.${slug}.${sid}.${ac}'
8082
},
8183
color: {

lib/file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ file.userHomeDir = function() {
2525
};
2626

2727
file.homeDir = function() {
28-
return path.join(this.userHomeDir(), '.lc');
28+
return path.join(this.userHomeDir(), '.lc-customized');
2929
};
3030

3131
file.appDir = function() {

lib/helper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const LANGS = [
3939
{lang: 'javascript', ext: '.js', style: 'c'},
4040
{lang: 'kotlin', ext: '.kt', style: 'c'},
4141
{lang: 'mysql', ext: '.sql', style: '--'},
42+
{lang: 'postgresql', ext: '.sql', style: '--'},
4243
{lang: 'php', ext: '.php', style: 'c'},
4344
{lang: 'python', ext: '.py', style: '#'},
4445
{lang: 'python3', ext: '.py', style: '#'},

0 commit comments

Comments
 (0)