github.com/c-darwin/mobile@v0.0.0-20160313183840-ff625c46f7c9/cmd/gobind/main.go (about)

     1  // Copyright 2014 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"flag"
     9  	"fmt"
    10  	"go/build"
    11  	"log"
    12  	"os"
    13  )
    14  
    15  var (
    16  	lang   = flag.String("lang", "java", "target language for bindings, either java, go, or objc (experimental).")
    17  	outdir = flag.String("outdir", "", "result will be written to the directory instead of stdout.")
    18  )
    19  
    20  var usage = `The Gobind tool generates Java language bindings for Go.
    21  
    22  For usage details, see doc.go.`
    23  
    24  func main() {
    25  	flag.Parse()
    26  
    27  	cwd, err := os.Getwd()
    28  	if err != nil {
    29  		log.Fatal(err)
    30  	}
    31  	for _, arg := range flag.Args() {
    32  		pkg, err := build.Import(arg, cwd, 0)
    33  		if err != nil {
    34  			fmt.Fprintf(os.Stderr, "%s: %v\n", arg, err)
    35  			os.Exit(1)
    36  		}
    37  		genPkg(pkg)
    38  	}
    39  	os.Exit(exitStatus)
    40  }
    41  
    42  var exitStatus = 0
    43  
    44  func errorf(format string, args ...interface{}) {
    45  	fmt.Fprintf(os.Stderr, format, args...)
    46  	fmt.Fprintln(os.Stderr)
    47  	exitStatus = 1
    48  }