aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-09-09 10:44:37 +0200
committerThomas Voss <mail@thomasvoss.com> 2023-09-09 10:44:37 +0200
commit0407c133037d522283bc53aa611677f821b234e3 (patch)
treee88f96654dc5846b46a95b0d7d3b1efebe2b5e21 /main.go
parentfc6d6410f16e56d39288deed424a642482e7ca2e (diff)
Support reading from stdin and multiple inputs
Diffstat (limited to 'main.go')
-rw-r--r--main.go28
1 files changed, 21 insertions, 7 deletions
diff --git a/main.go b/main.go
index 1da9ba1..1c94efa 100644
--- a/main.go
+++ b/main.go
@@ -9,15 +9,29 @@ import (
)
func main() {
- if len(os.Args) != 2 {
- fmt.Fprintf(os.Stderr, "Usage: %s file\n", os.Args[0])
- os.Exit(1)
+ if len(os.Args) == 1 {
+ process("-")
}
- file, err := os.Open(os.Args[1])
- if err != nil {
- die(err)
+
+ for _, arg := range os.Args[1:] {
+ process(arg)
+ }
+}
+
+func process(filename string) {
+ var file *os.File
+ var err error
+
+ if filename == "-" {
+ file = os.Stdin
+ } else {
+ file, err = os.Open(filename)
+ if err != nil {
+ die(err)
+ }
+ defer file.Close()
}
- defer file.Close()
+
ast, err := parser.ParseFile(file)
if err != nil {
die(err)