diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-05-19 05:38:51 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-05-19 05:39:27 -0400 |
commit | 83f436e175643da6d75e1de3fe905b586012bac2 (patch) | |
tree | f250b9fdaca68941863caad5c778bccdf45099ca /main.go | |
parent | aeb85efdad3dd705894386aa9aef5e22db1541b8 (diff) |
Command line flags
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -3,6 +3,8 @@ package main import ( "crypto/md5" "encoding/hex" + "flag" + "fmt" "github.com/golang/protobuf/proto" "github.com/ry/v8worker2" "io" @@ -17,6 +19,10 @@ import ( "time" ) +var flagReload = flag.Bool("reload", false, "Reload cached remote source code.") +var flagV8Options = flag.Bool("v8-options", false, "Print V8 command line options.") +var flagDebug = flag.Bool("debug", false, "Enable debug output.") + var DenoDir string var CompileDir string var SrcDir string @@ -44,12 +50,14 @@ func IsRemote(filename string) bool { // Fetches a remoteUrl but also caches it to the localFilename. func FetchRemoteSource(remoteUrl string, localFilename string) ([]byte, error) { + //println("FetchRemoteSource", remoteUrl) Assert(strings.HasPrefix(localFilename, SrcDir), localFilename) var sourceReader io.Reader file, err := os.Open(localFilename) - if os.IsNotExist(err) { + if *flagReload || os.IsNotExist(err) { // Fetch from HTTP. + println("Downloading", remoteUrl) res, err := http.Get(remoteUrl) if err != nil { return nil, err @@ -100,6 +108,7 @@ func ResolveModule(moduleSpecifier string, containingFile string) ( const assetPrefix string = "/$asset$/" func HandleSourceCodeFetch(moduleSpecifier string, containingFile string) (out []byte) { + Assert(moduleSpecifier != "", "moduleSpecifier shouldn't be empty") res := &Msg{} var sourceCodeBuf []byte var err error @@ -117,6 +126,9 @@ func HandleSourceCodeFetch(moduleSpecifier string, containingFile string) (out [ return } + //println("HandleSourceCodeFetch", "moduleSpecifier", moduleSpecifier, + // "containingFile", containingFile, "filename", filename) + if IsRemote(moduleName) { sourceCodeBuf, err = FetchRemoteSource(moduleName, filename) } else if strings.HasPrefix(moduleName, assetPrefix) { @@ -249,7 +261,14 @@ func recv(buf []byte) []byte { } func main() { - args := v8worker2.SetFlags(os.Args) + flag.Parse() + args := flag.Args() + if *flagV8Options { + args = append(args, "--help") + fmt.Println(args) + } + args = v8worker2.SetFlags(args) + createDirs() worker := v8worker2.New(recv) loadAsset(worker, "dist/main.js") @@ -262,8 +281,9 @@ func main() { out, err := proto.Marshal(&Msg{ Payload: &Msg_Start{ Start: &StartMsg{ - Cwd: cwd, - Argv: args, + Cwd: cwd, + Argv: args, + DebugFlag: *flagDebug, }, }, }) |