Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5c5b05a

Browse files
author
Openset
committed
Update: runReadme
1 parent 5bd8900 commit 5c5b05a

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

‎internal/readme/readme.go

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package readme
22

33
import (
4-
"bufio"
54
"bytes"
65
"fmt"
7-
"io"
86
"io/ioutil"
9-
"os"
107
"strings"
118

129
"github.com/openset/leetcode/internal/base"
@@ -20,31 +17,14 @@ var CmdReadme = &base.Command{
2017
Long: "build README.md file.",
2118
}
2219

23-
const (
24-
filename = "README.md"
25-
lineNum = 12
26-
)
27-
2820
func runReadme(cmd *base.Command, args []string) {
2921
if len(args) != 0 {
3022
cmd.Usage()
3123
}
3224
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)
4626
writeProblems(wb)
47-
err = ioutil.WriteFile(filename, wb.Bytes(), 0644)
27+
err := ioutil.WriteFile("README.md", wb.Bytes(), 0644)
4828
base.CheckErr(err)
4929
}
5030

@@ -69,3 +49,19 @@ func writeProblems(wb *bytes.Buffer) {
6949
}
7050
}
7151
}
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+
[![Build Status](https://travis-ci.org/openset/leetcode.svg?branch=master)](https://travis-ci.org/openset/leetcode)
59+
[![codecov](https://codecov.io/gh/openset/leetcode/branch/master/graph/badge.svg)](https://codecov.io/gh/openset/leetcode)
60+
[![Go Report Card](https://goreportcard.com/badge/github.com/openset/leetcode)](https://goreportcard.com/report/github.com/openset/leetcode)
61+
[![GitHub contributors](https://img.shields.io/github/contributors/openset/leetcode.svg)](https://github.com/openset/leetcode/graphs/contributors)
62+
[![license](https://img.shields.io/github/license/openset/leetcode.svg)](https://github.com/openset/leetcode/blob/master/LICENSE)
63+
[![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/openset/leetcode.svg?colorB=green)](https://github.com/openset/leetcode/archive/master.zip)
64+
65+
| # | Title | Solution | Difficulty |
66+
| :-: | - | - | :-: |
67+
`

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /