github.com/theodus/go-transpiler@v0.0.0-20160215204930-f7a111b512c0/cli.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"github.com/codegangsta/cli"
     8  )
     9  
    10  func main() {
    11  	app := cli.NewApp()
    12  	app.Name = "go-transpiler"
    13  	app.Author = "Theodore Butler"
    14  	app.Usage = "compile Go to Java, C++, or JS using tardisgo or gopherjs"
    15  	app.Version = "0.3.0"
    16  	app.Commands = []cli.Command{
    17  		{
    18  			Name:  "java",
    19  			Usage: "Compile Go source to Java target",
    20  			Action: func(ctx *cli.Context) {
    21  				if len(ctx.Args()) < 1 {
    22  					tardis("java", "")
    23  					return
    24  				}
    25  				if len(ctx.Args()) > 1 {
    26  					fmt.Println("Too many arguments!")
    27  					return
    28  				}
    29  				tardis("java", ctx.Args()[0])
    30  			},
    31  		}, {
    32  			Name:  "cpp",
    33  			Usage: "Compile Go source to C++ target",
    34  			Action: func(ctx *cli.Context) {
    35  				if len(ctx.Args()) < 1 {
    36  					tardis("cpp", "")
    37  					return
    38  				}
    39  				if len(ctx.Args()) > 1 {
    40  					fmt.Println("Too many arguments!")
    41  					return
    42  				}
    43  				tardis("cpp", ctx.Args()[0])
    44  			},
    45  		}, {
    46  			Name:  "js",
    47  			Usage: "Compile Go source to JS target",
    48  			Action: func(ctx *cli.Context) {
    49  				if len(ctx.Args()) < 1 {
    50  					gopherjs("")
    51  					return
    52  				}
    53  				if len(ctx.Args()) > 1 {
    54  					fmt.Println("Too many arguments!")
    55  					return
    56  				}
    57  				gopherjs(ctx.Args()[0])
    58  			},
    59  		},
    60  	}
    61  	app.Run(os.Args)
    62  }