Skip to content

Commit 38d5634

Browse files
Add -version to CLI (microsoft#834)
Co-authored-by: Jake Bailey <[email protected]>
1 parent d851a61 commit 38d5634

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cmd/tsgo/main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"os"
99
"runtime"
10+
"runtime/debug"
1011
"slices"
1112
"strconv"
1213
"strings"
@@ -59,6 +60,7 @@ type cliOptions struct {
5960
listFiles tristateFlag
6061
listFilesOnly tristateFlag
6162
showConfig tristateFlag
63+
version bool
6264
}
6365

6466
devel struct {
@@ -103,6 +105,7 @@ func parseArgs() *cliOptions {
103105
flag.Var(&opts.tsc.listFiles, "listFiles", diagnostics.Print_all_of_the_files_read_during_the_compilation.Format())
104106
flag.Var(&opts.tsc.listFilesOnly, "listFilesOnly", diagnostics.Print_names_of_files_that_are_part_of_the_compilation_and_then_stop_processing.Format())
105107
flag.Var(&opts.tsc.showConfig, "showConfig", diagnostics.Print_the_final_configuration_instead_of_building.Format())
108+
flag.BoolVar(&opts.tsc.version, "version", false, diagnostics.Print_the_compiler_s_version.Format())
106109

107110
flag.BoolVar(&opts.devel.quiet, "q", false, "Do not print diagnostics.")
108111
flag.BoolVar(&opts.devel.quiet, "quiet", false, "Do not print diagnostics.")
@@ -144,6 +147,21 @@ func runMain() int {
144147
defer profileSession.Stop()
145148
}
146149

150+
if opts.tsc.version {
151+
// Get build info to extract the commit SHA
152+
buildInfo, _ := debug.ReadBuildInfo()
153+
version := core.Version
154+
for _, setting := range buildInfo.Settings {
155+
if setting.Key == "vcs.revision" {
156+
version += "-" + setting.Value
157+
break
158+
}
159+
}
160+
161+
fmt.Println(diagnostics.Version_0.Format(version))
162+
return 0
163+
}
164+
147165
startTime := time.Now()
148166

149167
currentDirectory, err := os.Getwd()

0 commit comments

Comments
 (0)