@@ -727,81 +727,61 @@ func outsideSupportedRange(version string) bool {
727
727
return semver .Compare (short , "v" + minGoVersion ) < 0 || semver .Compare (short , "v" + maxGoVersion ) > 0
728
728
}
729
729
730
- // Check if `v.goModVersion` or `v.goEnvVersion` are outside of the supported range. If so, emit
731
- // a diagnostic and return an empty version to indicate that we should not attempt to install a
732
- // different version of Go.
733
- func checkForUnsupportedVersions (v versionInfo ) (msg , version string ) {
734
- if v .goModVersionFound && outsideSupportedRange (v .goModVersion ) {
735
- msg = "The version of Go found in the `go.mod` file (" + v .goModVersion +
736
- ") is outside of the supported range (" + minGoVersion + "-" + maxGoVersion +
737
- "). Writing an environment file not specifying any version of Go."
738
- version = ""
739
- diagnostics .EmitUnsupportedVersionGoMod (msg )
740
- }
741
-
742
- return msg , version
743
- }
744
-
745
- // Check if either `v.goEnvVersionFound` or `v.goModVersionFound` are false. If so, emit
746
- // a diagnostic and return the version to install, or the empty string if we should not attempt to
747
- // install a version of Go. We assume that `checkForUnsupportedVersions` has already been
748
- // called, so any versions that are found are within the supported range.
749
- func checkForVersionsNotFound (v versionInfo ) (msg , version string ) {
750
- if ! v .goEnvVersionFound && ! v .goModVersionFound {
730
+ // Assuming `v.goModVersionFound` is false, emit a diagnostic and return the version to install,
731
+ // or the empty string if we should not attempt to install a version of Go.
732
+ func checkForGoModVersionNotFound (v versionInfo ) (msg , version string ) {
733
+ if ! v .goEnvVersionFound {
751
734
msg = "No version of Go installed and no `go.mod` file found. Writing an environment " +
752
735
"file specifying the maximum supported version of Go (" + maxGoVersion + ")."
753
736
version = maxGoVersion
754
737
diagnostics .EmitNoGoModAndNoGoEnv (msg )
755
- }
756
-
757
- if ! v .goEnvVersionFound && v .goModVersionFound {
758
- msg = "No version of Go installed. Writing an environment file specifying the version " +
759
- "of Go found in the `go.mod` file (" + v .goModVersion + ")."
760
- version = v .goModVersion
761
- diagnostics .EmitNoGoEnv (msg )
762
- }
763
-
764
- if v .goEnvVersionFound && ! v .goModVersionFound {
765
- if outsideSupportedRange (v .goEnvVersion ) {
766
- msg = "No `go.mod` file found. The version of Go installed in the environment (" +
767
- v .goEnvVersion + ") is outside of the supported range (" + minGoVersion + "-" +
768
- maxGoVersion + "). Writing an environment file specifying the maximum supported " +
769
- "version of Go (" + maxGoVersion + ")."
770
- version = maxGoVersion
771
- diagnostics .EmitNoGoModAndGoEnvUnsupported (msg )
772
- } else {
773
- msg = "No `go.mod` file found. Version " + v .goEnvVersion + " installed in the " +
774
- "environment is supported. Writing an environment file not specifying any " +
775
- "version of Go."
776
- version = ""
777
- diagnostics .EmitNoGoModAndGoEnvSupported (msg )
778
- }
738
+ } else if outsideSupportedRange (v .goEnvVersion ) {
739
+ msg = "No `go.mod` file found. The version of Go installed in the environment (" +
740
+ v .goEnvVersion + ") is outside of the supported range (" + minGoVersion + "-" +
741
+ maxGoVersion + "). Writing an environment file specifying the maximum supported " +
742
+ "version of Go (" + maxGoVersion + ")."
743
+ version = maxGoVersion
744
+ diagnostics .EmitNoGoModAndGoEnvUnsupported (msg )
745
+ } else {
746
+ msg = "No `go.mod` file found. Version " + v .goEnvVersion + " installed in the " +
747
+ "environment is supported. Writing an environment file not specifying any " +
748
+ "version of Go."
749
+ version = ""
750
+ diagnostics .EmitNoGoModAndGoEnvSupported (msg )
779
751
}
780
752
781
753
return msg , version
782
754
}
783
755
784
- // Compare `v.goModVersion` and `v.goEnvVersion`. emit a diagnostic and return the version to
785
- // install, or the empty string if we should not attempt to install a version of Go. We assume that
786
- // `checkForUnsupportedVersions` and `checkForVersionsNotFound` have already been called, so both
787
- // versions are found and are within the supported range.
788
- func compareVersions (v versionInfo ) (msg , version string ) {
789
- if semver .Compare ("v" + v .goModVersion , "v" + v .goEnvVersion ) > 0 {
790
- msg = "The version of Go installed in the environment (" + v .goEnvVersion +
791
- ") is lower than the version found in the `go.mod` file (" + v .goModVersion +
792
- "). Writing an environment file specifying the version of Go from the `go.mod` " +
793
- "file (" + v .goModVersion + ")."
756
+ // Assuming `v.goModVersionFound` is true, emit a diagnostic and return the version to install,
757
+ // or the empty string if we should not attempt to install a version of Go.
758
+ func checkForGoModVersionFound (v versionInfo ) (msg , version string ) {
759
+ if outsideSupportedRange (v .goModVersion ) {
760
+ msg = "The version of Go found in the `go.mod` file (" + v .goModVersion +
761
+ ") is outside of the supported range (" + minGoVersion + "-" + maxGoVersion +
762
+ "). Writing an environment file not specifying any version of Go."
763
+ version = ""
764
+ diagnostics .EmitUnsupportedVersionGoMod (msg )
765
+ } else if ! v .goEnvVersionFound {
766
+ msg = "No version of Go installed. Writing an environment file specifying the version " +
767
+ "of Go found in the `go.mod` file (" + v .goModVersion + ")."
794
768
version = v .goModVersion
795
- diagnostics .EmitVersionGoModHigherVersionEnvironment (msg )
769
+ diagnostics .EmitNoGoEnv (msg )
796
770
} else if outsideSupportedRange (v .goEnvVersion ) {
797
771
msg = "The version of Go installed in the environment (" + v .goEnvVersion +
798
772
") is outside of the supported range (" + minGoVersion + "-" + maxGoVersion + "). " +
799
773
"Writing an environment file specifying the version of Go from the `go.mod` file (" +
800
774
v .goModVersion + ")."
801
775
version = v .goModVersion
802
776
diagnostics .EmitVersionGoModSupportedAndGoEnvUnsupported (msg )
777
+ } else if semver .Compare ("v" + v .goModVersion , "v" + v .goEnvVersion ) > 0 {
778
+ msg = "The version of Go installed in the environment (" + v .goEnvVersion +
779
+ ") is lower than the version found in the `go.mod` file (" + v .goModVersion +
780
+ "). Writing an environment file specifying the version of Go from the `go.mod` " +
781
+ "file (" + v .goModVersion + ")."
782
+ version = v .goModVersion
783
+ diagnostics .EmitVersionGoModHigherVersionEnvironment (msg )
803
784
} else {
804
-
805
785
msg = "The version of Go installed in the environment (" + v .goEnvVersion +
806
786
") is supported and is high enough for the version found in the `go.mod` file (" +
807
787
v .goModVersion + "). Writing an environment file not specifying any version of Go."
@@ -815,18 +795,11 @@ func compareVersions(v versionInfo) (msg, version string) {
815
795
// Check the versions of Go found in the environment and in the `go.mod` file, and return a
816
796
// version to install. If the version is the empty string then no installation is required.
817
797
func getVersionToInstall (v versionInfo ) (msg , version string ) {
818
- msg , version = checkForUnsupportedVersions (v )
819
- if msg != "" {
820
- return msg , version
798
+ if ! v .goModVersionFound {
799
+ return checkForGoModVersionNotFound (v )
821
800
}
822
801
823
- msg , version = checkForVersionsNotFound (v )
824
- if msg != "" {
825
- return msg , version
826
- }
827
-
828
- msg , version = compareVersions (v )
829
- return msg , version
802
+ return checkForGoModVersionFound (v )
830
803
}
831
804
832
805
// Write an environment file to the current directory. If `version` is the empty string then
0 commit comments