|
7 | 7 | "fmt"
|
8 | 8 | "os"
|
9 | 9 | "runtime"
|
| 10 | + "runtime/debug" |
10 | 11 | "slices"
|
11 | 12 | "strconv"
|
12 | 13 | "strings"
|
@@ -59,6 +60,7 @@ type cliOptions struct {
|
59 | 60 | listFiles tristateFlag
|
60 | 61 | listFilesOnly tristateFlag
|
61 | 62 | showConfig tristateFlag
|
| 63 | + version bool |
62 | 64 | }
|
63 | 65 |
|
64 | 66 | devel struct {
|
@@ -103,6 +105,7 @@ func parseArgs() *cliOptions {
|
103 | 105 | flag.Var(&opts.tsc.listFiles, "listFiles", diagnostics.Print_all_of_the_files_read_during_the_compilation.Format())
|
104 | 106 | flag.Var(&opts.tsc.listFilesOnly, "listFilesOnly", diagnostics.Print_names_of_files_that_are_part_of_the_compilation_and_then_stop_processing.Format())
|
105 | 107 | 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()) |
106 | 109 |
|
107 | 110 | flag.BoolVar(&opts.devel.quiet, "q", false, "Do not print diagnostics.")
|
108 | 111 | flag.BoolVar(&opts.devel.quiet, "quiet", false, "Do not print diagnostics.")
|
@@ -144,6 +147,21 @@ func runMain() int {
|
144 | 147 | defer profileSession.Stop()
|
145 | 148 | }
|
146 | 149 |
|
| 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 | + |
147 | 165 | startTime := time.Now()
|
148 | 166 |
|
149 | 167 | currentDirectory, err := os.Getwd()
|
|
0 commit comments