37 lines
712 B
Go
37 lines
712 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/Xe/ln"
|
|
)
|
|
|
|
func main() {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
flag.Parse()
|
|
|
|
if flag.NArg() != 1 {
|
|
ln.Fatal(ctx, ln.Info("please pass a webassembly file to run"))
|
|
}
|
|
|
|
fname := flag.Arg(0)
|
|
fin, err := os.Open(fname)
|
|
if err != nil {
|
|
ln.FatalErr(ctx, err, ln.F{"msg": "can't open file", "fname": fname})
|
|
}
|
|
defer fin.Close()
|
|
|
|
p, err := NewProcess(fin, fname)
|
|
if err != nil {
|
|
ln.FatalErr(ctx, err, ln.F{"msg": "can't create process", "fname": fname})
|
|
}
|
|
|
|
returnCode, err := p.Main()
|
|
|
|
ln.Log(ctx, ln.Info("process returned code"), ln.F{"code": returnCode, "type": fmt.Sprintf("%T", returnCode)})
|
|
}
|