1
1
package readme
2
2
3
3
import (
4
- "bufio"
5
4
"bytes"
6
5
"fmt"
7
- "io"
8
6
"io/ioutil"
9
- "os"
10
7
"strings"
11
8
12
9
"github.com/openset/leetcode/internal/base"
@@ -20,31 +17,14 @@ var CmdReadme = &base.Command{
20
17
Long : "build README.md file." ,
21
18
}
22
19
23
- const (
24
- filename = "README.md"
25
- lineNum = 12
26
- )
27
-
28
20
func runReadme (cmd * base.Command , args []string ) {
29
21
if len (args ) != 0 {
30
22
cmd .Usage ()
31
23
}
32
24
wb := bytes .NewBuffer (nil )
33
- f , err := os .OpenFile (filename , os .O_RDWR | os .O_CREATE , 0666 )
34
- base .CheckErr (err )
35
- defer f .Close ()
36
- rb := bufio .NewReader (f )
37
- for ln := 0 ; ln < lineNum ; ln ++ {
38
- line , _ , err := rb .ReadLine ()
39
- if err == io .EOF {
40
- break
41
- }
42
- base .CheckErr (err )
43
- wb .Write (line )
44
- wb .WriteString ("\n " )
45
- }
25
+ wb .WriteString (defaultStr )
46
26
writeProblems (wb )
47
- err = ioutil .WriteFile (filename , wb .Bytes (), 0644 )
27
+ err : = ioutil .WriteFile ("README.md" , wb .Bytes (), 0644 )
48
28
base .CheckErr (err )
49
29
}
50
30
@@ -69,3 +49,19 @@ func writeProblems(wb *bytes.Buffer) {
69
49
}
70
50
}
71
51
}
52
+
53
+ const defaultStr = `<!--This file generated by command(leetcode readme); DO NOT EDIT.-->
54
+
55
+ # [LeetCode](https://openset.github.io/leetcode)
56
+ LeetCode Problems' Solutions
57
+
58
+ [](https://travis-ci.org/openset/leetcode)
59
+ [](https://codecov.io/gh/openset/leetcode)
60
+ [](https://goreportcard.com/report/github.com/openset/leetcode)
61
+ [](https://github.com/openset/leetcode/graphs/contributors)
62
+ [](https://github.com/openset/leetcode/blob/master/LICENSE)
63
+ [](https://github.com/openset/leetcode/archive/master.zip)
64
+
65
+ | # | Title | Solution | Difficulty |
66
+ | :-: | - | - | :-: |
67
+ `
0 commit comments