add tool/measure
This commit is contained in:
parent
fe4b7ffd45
commit
0829ebc996
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
build
|
build
|
||||||
tool/generate
|
tool/build-html-inner
|
||||||
tool/number
|
tool/number
|
||||||
|
tool/measure-inner
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
ls src/0*/*.{go,sh} | xargs tool/generate > build/go-by-example.html
|
ls src/0*/*.{go,sh} | xargs tool/build-html-inner > build/go-by-example.html
|
||||||
|
@ -2,5 +2,6 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
go build -o tool/generate tool/src/generate.go
|
go build -o tool/build-html-inner tool/src/build-html-inner.go
|
||||||
go build -o tool/number tool/src/number.go
|
go build -o tool/number tool/src/number.go
|
||||||
|
go build -o tool/measure-inner tool/src/measure-inner.go
|
||||||
|
6
tool/measure
Executable file
6
tool/measure
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
ls src/0*/*.{go,sh} | xargs tool/measure-inner
|
@ -1,5 +1,3 @@
|
|||||||
// Generate an HTML file from the book source. Derived from golit.
|
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
42
tool/src/measure-inner.go
Normal file
42
tool/src/measure-inner.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func check(err error) {
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func readLines(path string) []string {
|
||||||
|
srcBytes, err := ioutil.ReadFile(path)
|
||||||
|
check(err)
|
||||||
|
return strings.Split(string(srcBytes), "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if len(os.Args) <= 1 {
|
||||||
|
fmt.Fprintln(os.Stderr, "usage: tool/measure *.{go,sh}")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
foundLongFile := false
|
||||||
|
for _, sourcePath := range os.Args[1:] {
|
||||||
|
foundLongLine := false
|
||||||
|
lines := readLines(sourcePath)
|
||||||
|
for _, line := range lines {
|
||||||
|
if len(line) > 60 && !foundLongLine {
|
||||||
|
fmt.Println(sourcePath)
|
||||||
|
foundLongLine = true
|
||||||
|
foundLongFile = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if foundLongFile {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user