Skip to content

Commit 45518c1

Browse files
authored
Add GopherJS compiler version and command to print it. (#501)
The version being referred to is the GopherJS compiler version, not not the GopherJS build tool. That's why the canonical version string is located in the compiler package. The build tool's version is less important and it effectively takes on the version of the compiler. Helps #500.
1 parent b33dd36 commit 45518c1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/version_check.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
package compiler
55

66
const ___GOPHERJS_REQUIRES_GO_VERSION_1_7___ = true
7+
8+
// Version is the GopherJS compiler version string.
9+
const Version = "1.7-1"

tool.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,24 @@ func main() {
508508
fmt.Fprintln(os.Stderr, http.Serve(tcpKeepAliveListener{ln.(*net.TCPListener)}, sourceFiles))
509509
}
510510

511+
cmdVersion := &cobra.Command{
512+
Use: "version",
513+
Short: "print GopherJS compiler version",
514+
}
515+
cmdVersion.Run = func(cmd *cobra.Command, args []string) {
516+
if len(args) > 0 {
517+
cmdServe.HelpFunc()(cmd, args)
518+
os.Exit(1)
519+
}
520+
521+
fmt.Printf("GopherJS %s\n", compiler.Version)
522+
}
523+
511524
rootCmd := &cobra.Command{
512525
Use: "gopherjs",
513526
Long: "GopherJS is a tool for compiling Go source code to JavaScript.",
514527
}
515-
rootCmd.AddCommand(cmdBuild, cmdGet, cmdInstall, cmdRun, cmdTest, cmdServe)
528+
rootCmd.AddCommand(cmdBuild, cmdGet, cmdInstall, cmdRun, cmdTest, cmdServe, cmdVersion)
516529
rootCmd.Execute()
517530
}
518531

0 commit comments

Comments
 (0)