Skip to content

Commit 42f1589

Browse files
authored
Port version printing from strada (#634)
1 parent 41b535e commit 42f1589

8 files changed

+18
-8
lines changed

internal/execute/outputs.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/microsoft/typescript-go/internal/ast"
88
"github.com/microsoft/typescript-go/internal/compiler"
9+
"github.com/microsoft/typescript-go/internal/compiler/diagnostics"
910
"github.com/microsoft/typescript-go/internal/core"
1011
"github.com/microsoft/typescript-go/internal/diagnosticwriter"
1112
"github.com/microsoft/typescript-go/internal/tspath"
@@ -79,3 +80,8 @@ type statistic struct {
7980
func newStatistic(name string, count int) statistic {
8081
return statistic{name, count}
8182
}
83+
84+
func printVersion(sys System) {
85+
fmt.Fprint(sys.Writer(), diagnostics.Version_0.Format(core.Version)+sys.NewLine())
86+
sys.EndWrite()
87+
}

internal/execute/tsc.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@ func executeCommandLineWorker(sys System, cb cbType, commandLine *tsoptions.Pars
3535
}
3636

3737
if commandLine.CompilerOptions().Init.IsTrue() ||
38-
commandLine.CompilerOptions().Version.IsTrue() ||
3938
// commandLine.CompilerOptions().Help != nil ||
4039
// commandLine.CompilerOptions().All != nil ||
4140
commandLine.CompilerOptions().Watch.IsTrue() && commandLine.CompilerOptions().ListFilesOnly.IsTrue() {
4241
return ExitStatusNotImplemented, nil
4342
}
4443

44+
if commandLine.CompilerOptions().Version.IsTrue() {
45+
printVersion(sys)
46+
return ExitStatusSuccess, nil
47+
}
48+
4549
if commandLine.CompilerOptions().Project != "" {
4650
if len(commandLine.FileNames()) != 0 {
4751
reportDiagnostic(ast.NewCompilerDiagnostic(diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line))
@@ -71,7 +75,7 @@ func executeCommandLineWorker(sys System, cb cbType, commandLine *tsoptions.Pars
7175
if commandLine.CompilerOptions().ShowConfig.IsTrue() {
7276
reportDiagnostic(ast.NewCompilerDiagnostic(diagnostics.Cannot_find_a_tsconfig_json_file_at_the_current_directory_Colon_0, tspath.NormalizePath(sys.GetCurrentDirectory())))
7377
} else {
74-
// print version
78+
printVersion(sys)
7579
// print help
7680
}
7781
return ExitStatusDiagnosticsPresent_OutputsSkipped, nil

testdata/baselines/reference/tsc/commandLine/Parse-watch-interval-option.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,5 @@ ParsedCommandLine::{
152152
"compileOnSave": null
153153
}
154154
Output::
155-
No output
155+
Version 7.0.0-dev
156156

testdata/baselines/reference/tsc/commandLine/does-not-add-color-when-NO_COLOR-is-set.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,5 @@ ParsedCommandLine::{
149149
"compileOnSave": null
150150
}
151151
Output::
152-
No output
152+
Version 7.0.0-dev
153153

testdata/baselines/reference/tsc/commandLine/help-all.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,5 @@ ParsedCommandLine::{
152152
"compileOnSave": null
153153
}
154154
Output::
155-
No output
155+
Version 7.0.0-dev
156156

testdata/baselines/reference/tsc/commandLine/help.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,5 @@ ParsedCommandLine::{
151151
"compileOnSave": null
152152
}
153153
Output::
154-
No output
154+
Version 7.0.0-dev
155155

testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-cannot-provide-terminal-width.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,5 @@ ParsedCommandLine::{
149149
"compileOnSave": null
150150
}
151151
Output::
152-
No output
152+
Version 7.0.0-dev
153153

testdata/baselines/reference/tsc/commandLine/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,5 @@ ParsedCommandLine::{
149149
"compileOnSave": null
150150
}
151151
Output::
152-
No output
152+
Version 7.0.0-dev
153153

0 commit comments

Comments
 (0)