add tool/measure

This commit is contained in:
Mark McGranaghan 2012-10-01 17:26:19 -07:00
parent fe4b7ffd45
commit 0829ebc996
7 changed files with 54 additions and 6 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
build
tool/generate
tool/build-html-inner
tool/number
tool/measure-inner

View File

@ -64,7 +64,7 @@ func generateWrites(writes chan *writeOp) {
key := randKey()
val := randVal()
write := &writeOp{
key: key,
key: key,
val: val,
resp: make(chan bool)}
writes <- write

View File

@ -1,3 +1,3 @@
#!/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

View File

@ -2,5 +2,6 @@
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/measure-inner tool/src/measure-inner.go

6
tool/measure Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
set -e
set -o pipefail
ls src/0*/*.{go,sh} | xargs tool/measure-inner

View File

@ -1,5 +1,3 @@
// Generate an HTML file from the book source. Derived from golit.
package main
import (

42
tool/src/measure-inner.go Normal file
View 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)
}
}