File tree 4 files changed +55
-1
lines changed
4 files changed +55
-1
lines changed Original file line number Diff line number Diff line change
1
+ <!-- This file generated by command(leetcode helper); DO NOT EDIT.-->
2
+
1
3
# Helper
2
4
3
5
``` text
7
9
leetcode <command> [arguments]
8
10
The commands are:
9
11
readme build README.md file
12
+ helper build helper file
13
+ question build problem description file
10
14
test run go test
11
15
update update self
16
+ description build all problems description file
12
17
version print leetcode version
13
18
help show command usage
14
19
Original file line number Diff line number Diff line change @@ -2,7 +2,9 @@ package base
2
2
3
3
import (
4
4
"fmt"
5
+ "io/ioutil"
5
6
"os"
7
+ "path"
6
8
"strings"
7
9
)
8
10
@@ -51,6 +53,21 @@ func Usage() {
51
53
Exit ()
52
54
}
53
55
56
+ func FilePutContents (filename string , data []byte ) {
57
+ filename = getFilePath (filename )
58
+ err := ioutil .WriteFile (filename , data , 0644 )
59
+ CheckErr (err )
60
+ }
61
+
62
+ func getFilePath (filename string ) string {
63
+ if dir := path .Dir (filename ); dir != "" {
64
+ if err := os .MkdirAll (dir , 0755 ); err != nil {
65
+ CheckErr (err )
66
+ }
67
+ }
68
+ return filename
69
+ }
70
+
54
71
func CheckErr (err error ) {
55
72
if err != nil {
56
73
panic (err )
Original file line number Diff line number Diff line change
1
+ package helper
2
+
3
+ import (
4
+ "bytes"
5
+ "os/exec"
6
+
7
+ "github.com/openset/leetcode/internal/base"
8
+ )
9
+
10
+ var CmdHelper = & base.Command {
11
+ Run : runHelper ,
12
+ UsageLine : "helper" ,
13
+ Short : "build helper file" ,
14
+ Long : "build helper README.md file." ,
15
+ }
16
+
17
+ func runHelper (cmd * base.Command , args []string ) {
18
+ if len (args ) != 0 {
19
+ cmd .Usage ()
20
+ }
21
+ var bf bytes.Buffer
22
+ bf .WriteString ("<!--This file generated by command(leetcode helper); DO NOT EDIT.-->\n \n " )
23
+ bf .WriteString ("# Helper\n \n " )
24
+ bf .WriteString ("```text\n " )
25
+ out , err := exec .Command (base .CmdName ).Output ()
26
+ base .CheckErr (err )
27
+ bf .Write (out )
28
+ bf .WriteString ("```\n " )
29
+ base .FilePutContents ("helper/README.md" , bf .Bytes ())
30
+ }
Original file line number Diff line number Diff line change 8
8
"github.com/openset/leetcode/internal/base"
9
9
"github.com/openset/leetcode/internal/description"
10
10
"github.com/openset/leetcode/internal/help"
11
+ "github.com/openset/leetcode/internal/helper"
11
12
"github.com/openset/leetcode/internal/question"
12
13
"github.com/openset/leetcode/internal/readme"
13
14
"github.com/openset/leetcode/internal/test"
@@ -19,9 +20,10 @@ func init() {
19
20
base .Commands = []* base.Command {
20
21
readme .CmdReadme ,
21
22
question .CmdQuestion ,
23
+ description .CmdDescription ,
22
24
test .CmdTest ,
23
25
update .CmdUpdate ,
24
- description . CmdDescription ,
26
+ helper . CmdHelper ,
25
27
version .CmdVersion ,
26
28
help .CmdHelp ,
27
29
}
You can’t perform that action at this time.
0 commit comments