fix: skip first arg to set command line as expected by interpreted main (#203)

This commit is contained in:
Marc Vertes
2019-06-03 17:25:04 +02:00
committed by Ludovic Fernandez
parent ad009959af
commit 99eac2d333
2 changed files with 16 additions and 0 deletions

14
_test/flag0.go Normal file
View File

@@ -0,0 +1,14 @@
package main
import (
"flag"
"fmt"
)
func main() {
flag.Parse()
fmt.Println("Narg:", flag.NArg())
}
// Output:
// Narg: 0

View File

@@ -46,6 +46,8 @@ func main() {
}
if len(args) > 0 {
// Skip first os arg to set command line as expected by interpreted main
os.Args = os.Args[1:]
b, err := ioutil.ReadFile(args[0])
if err != nil {
log.Fatal("Could not read file: ", args[0])