Skip to content

Commit 26c0ce0

Browse files
committed
Add check format
1 parent 962ec8f commit 26c0ce0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

zlang.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
76
"os"
87
"strings"
98
"time"
@@ -31,7 +30,7 @@ func showErrorSource(source []byte, pos tokenizer.Position, dividerLen int) {
3130

3231
func main() {
3332
if len(os.Args) < 2 || (os.Args[1] == "-stats" && len(os.Args) < 3) {
34-
fmt.Printf("usage: zlang [-stats] source_filename\n")
33+
fmt.Printf("usage: zlang [-stats] source_filename.z\n")
3534
os.Exit(1)
3635
}
3736
showStats := false
@@ -42,8 +41,14 @@ func main() {
4241
filename = os.Args[2]
4342
execArgs = os.Args[3:]
4443
}
44+
// check format file
45+
name := strings.Split(filename, "/")[len(strings.Split(filename, "/"))-1]
46+
if strings.Split(name, ".")[len(strings.Split(name, "."))-1] != "z" {
47+
fmt.Printf("error: %q is not a zlang file\n", os.Args[1])
48+
os.Exit(1)
49+
}
4550

46-
input, err := ioutil.ReadFile(filename)
51+
input, err := os.ReadFile(filename)
4752
if err != nil {
4853
fmt.Printf("error reading %q\n", os.Args[1])
4954
os.Exit(1)

0 commit comments

Comments
 (0)