feature: set default GOPATH for command line and allow self interpreting (#240)
This commit is contained in:
committed by
Ludovic Fernandez
parent
8ee5cbd7aa
commit
3528b4539d
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go/build"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@@ -24,13 +25,15 @@ func main() {
|
|||||||
args := flag.Args()
|
args := flag.Args()
|
||||||
log.SetFlags(log.Lshortfile)
|
log.SetFlags(log.Lshortfile)
|
||||||
|
|
||||||
i := interp.New(interp.Options{})
|
i := interp.New(interp.Options{GoPath: build.Default.GOPATH})
|
||||||
i.Use(stdlib.Symbols)
|
i.Use(stdlib.Symbols)
|
||||||
i.Use(interp.Symbols)
|
i.Use(interp.Symbols)
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
// Skip first os arg to set command line as expected by interpreted main
|
// Skip first os arg to set command line as expected by interpreted main
|
||||||
os.Args = os.Args[1:]
|
os.Args = os.Args[1:]
|
||||||
|
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
|
||||||
|
|
||||||
b, err := ioutil.ReadFile(args[0])
|
b, err := ioutil.ReadFile(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Could not read file: ", args[0])
|
log.Fatal("Could not read file: ", args[0])
|
||||||
|
|||||||
@@ -5,6 +5,12 @@ import "reflect"
|
|||||||
// Symbols variable stores the map of stdlib symbols per package
|
// Symbols variable stores the map of stdlib symbols per package
|
||||||
var Symbols = map[string]map[string]reflect.Value{}
|
var Symbols = map[string]map[string]reflect.Value{}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Symbols["github.com/containous/yaegi/stdlib"] = map[string]reflect.Value{
|
||||||
|
"Symbols": reflect.ValueOf(Symbols),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Provide access to go standard library (http://golang.org/pkg/)
|
// Provide access to go standard library (http://golang.org/pkg/)
|
||||||
|
|
||||||
//go:generate ../cmd/goexports/goexports archive/tar archive/zip
|
//go:generate ../cmd/goexports/goexports archive/tar archive/zip
|
||||||
|
|||||||
@@ -5,4 +5,10 @@ import "reflect"
|
|||||||
// Symbols stores the map of syscall package symbols
|
// Symbols stores the map of syscall package symbols
|
||||||
var Symbols = map[string]map[string]reflect.Value{}
|
var Symbols = map[string]map[string]reflect.Value{}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Symbols["github.com/containous/yaegi/stdlib/syscall"] = map[string]reflect.Value{
|
||||||
|
"Symbols": reflect.ValueOf(Symbols),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//go:generate ../../cmd/goexports/goexports syscall
|
//go:generate ../../cmd/goexports/goexports syscall
|
||||||
|
|||||||
@@ -5,4 +5,10 @@ import "reflect"
|
|||||||
// Symbols stores the map of unsafe package symbols
|
// Symbols stores the map of unsafe package symbols
|
||||||
var Symbols = map[string]map[string]reflect.Value{}
|
var Symbols = map[string]map[string]reflect.Value{}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Symbols["github.com/containous/yaegi/stdlib/unsafe"] = map[string]reflect.Value{
|
||||||
|
"Symbols": reflect.ValueOf(Symbols),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//go:generate ../../cmd/goexports/goexports unsafe
|
//go:generate ../../cmd/goexports/goexports unsafe
|
||||||
|
|||||||
Reference in New Issue
Block a user