From a5c1d40790dd1386e85e61d4ddf3cc35266a48a1 Mon Sep 17 00:00:00 2001 From: kbrx93 Date: Sun, 16 Jan 2022 14:46:10 +0800 Subject: [PATCH] feat: support Java --- README.md | 3 ++- cmd/new/main.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 28e4d5e..d8b8c5c 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ $ leetcode-tool help ```js { - "lang": "go", // 项目全局语言, 配置后 new 命令 --lang 参数可省略, 目前支持 go ts js py3 + "lang": "go", // 项目全局语言, 配置后 new 命令 --lang 参数可省略, 目前支持 go ts js py3 java "cookie": "xxx" } ``` @@ -41,6 +41,7 @@ $ leetcode-tool help - Typescript ts - Javascript js - Python3 py3 +- Java java ## 主要功能 diff --git a/cmd/new/main.go b/cmd/new/main.go index 5288268..0ced603 100644 --- a/cmd/new/main.go +++ b/cmd/new/main.go @@ -49,6 +49,10 @@ var ( LeetcodeLang: "Python3", TplFiles: []TplFile{{"code", "solve_%s.py", codeStrPy3}, {"test", "test_%s.py", testCodeStrPy3}, {"__init__", "__init__.py", ""}}, }, + "java": { + LeetcodeLang: "Java", + TplFiles: []TplFile{{"code", "solve_%s.java", codeStrJava}, {"test", "test_%s.java", testCodeStrJava}}, + }, } ) @@ -212,3 +216,29 @@ var ( pass ` ) + +var ( + codeStrJava = `package {{ .Folder }}; + +/** + * @index {{ .Index }} + * @title {{ .Title }} + * @difficulty {{ .Difficulty }} + * @tags {{ .TagStr }} + * @draft false + * @link {{ .Link }} + * @frontendId {{ .FrontendId }} +*/ +{{ .Code }} +` + + testCodeStrJava = `package {{ .Folder }}; + +public class test_{{ printf "%04s" .Index }} { + public static void main(String[] args) { + Solution solution = new Solution(); + // do some test + } +} +` +) \ No newline at end of file