-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
44 lines (35 loc) · 653 Bytes
/
Copy pathmain.go
File metadata and controls
44 lines (35 loc) · 653 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Command mathfmt formats mathematical documentation.
package main
import (
"flag"
"io/ioutil"
"log"
"os"
)
var write = flag.Bool("w", false, "write result to (source) file instead of stdout")
func main() {
log.SetPrefix("mathfmt: ")
log.SetFlags(0)
flag.Parse()
for _, filename := range flag.Args() {
process(filename)
}
}
func process(filename string) {
src, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal(err)
}
b, err := Format(src)
if err != nil {
log.Fatal(err)
}
if *write {
err = ioutil.WriteFile(filename, b, 0o644)
} else {
_, err = os.Stdout.Write(b)
}
if err != nil {
log.Fatal(err)
}
}