@@ -740,7 +740,7 @@ func outsideSupportedRange(version string) bool {
740
740
741
741
// Assuming `v.goModVersionFound` is false, emit a diagnostic and return the version to install,
742
742
// or the empty string if we should not attempt to install a version of Go.
743
- func checkForGoModVersionNotFound (v versionInfo ) (msg , version string ) {
743
+ func getVersionWhenGoModVersionNotFound (v versionInfo ) (msg , version string ) {
744
744
if ! v .goEnvVersionFound {
745
745
// We definitely need to install a version. We have no indication which version was
746
746
// intended to be used to build this project. Go versions are generally backwards
@@ -773,87 +773,96 @@ func checkForGoModVersionNotFound(v versionInfo) (msg, version string) {
773
773
return msg , version
774
774
}
775
775
776
- // Assuming `v.goModVersionFound` is true, emit a diagnostic and return the version to install,
777
- // or the empty string if we should not attempt to install a version of Go.
778
- func checkForGoModVersionFound (v versionInfo ) (msg , version string ) {
779
- if aboveSupportedRange (v .goModVersion ) {
780
- // The project is intended to be built with a version of Go that is above the supported
781
- // range. We do not install a version of Go.
776
+ // Assuming `v.goModVersion` is above the supported range, emit a diagnostic and return the
777
+ // version to install, or the empty string if we should not attempt to install a version of Go.
778
+ func getVersionWhenGoModVersionTooHigh (v versionInfo ) (msg , version string ) {
779
+ // The project is intended to be built with a version of Go that is above the supported
780
+ // range. We do not install a version of Go.
781
+ msg = "The version of Go found in the `go.mod` file (" + v .goModVersion +
782
+ ") is above the supported range (" + minGoVersion + "-" + maxGoVersion +
783
+ "). Writing an environment file not specifying any version of Go."
784
+ version = ""
785
+ diagnostics .EmitUnsupportedVersionGoMod (msg )
786
+
787
+ return msg , version
788
+ }
789
+
790
+ // Assuming `v.goModVersion` is above the supported range, emit a diagnostic and return the
791
+ // version to install, or the empty string if we should not attempt to install a version of Go.
792
+ func getVersionWhenGoModVersionTooLow (v versionInfo ) (msg , version string ) {
793
+ if ! v .goEnvVersionFound {
794
+ // There is no Go version installed. The version in the `go.mod` file is below the
795
+ // supported range. Go versions are generally backwards compatible, so we install the
796
+ // minimum supported version.
782
797
msg = "The version of Go found in the `go.mod` file (" + v .goModVersion +
783
- ") is above the supported range (" + minGoVersion + "-" + maxGoVersion +
784
- "). Writing an environment file not specifying any version of Go."
798
+ ") is below the supported range (" + minGoVersion + "-" + maxGoVersion +
799
+ "). No version of Go installed. Writing an environment file specifying the " +
800
+ "minimum supported version of Go (" + minGoVersion + ")."
801
+ version = minGoVersion
802
+ diagnostics .EmitNoGoEnv (msg )
803
+ } else if outsideSupportedRange (v .goEnvVersion ) {
804
+ // The version of Go that is installed is outside of the supported range. The version
805
+ // in the `go.mod` file is below the supported range. Go versions are generally
806
+ // backwards compatible, so we install the minimum supported version.
807
+ msg = "The version of Go found in the `go.mod` file (" + v .goModVersion +
808
+ ") is below the supported range (" + minGoVersion + "-" + maxGoVersion +
809
+ "). The version of Go installed in the environment (" + v .goEnvVersion +
810
+ ") is outside of the supported range (" + minGoVersion + "-" + maxGoVersion + "). " +
811
+ "Writing an environment file specifying the minimum supported version of Go (" +
812
+ minGoVersion + ")."
813
+ version = minGoVersion
814
+ diagnostics .EmitVersionGoModSupportedAndGoEnvUnsupported (msg )
815
+ } else {
816
+ // The version of Go that is installed is supported. The version in the `go.mod` file is
817
+ // below the supported range. We do not install a version of Go.
818
+ msg = "The version of Go installed in the environment (" + v .goEnvVersion +
819
+ ") is supported and is high enough for the version found in the `go.mod` file (" +
820
+ v .goModVersion + "). Writing an environment file not specifying any version of Go."
785
821
version = ""
786
- diagnostics .EmitUnsupportedVersionGoMod (msg )
787
- } else if belowSupportedRange (v .goModVersion ) {
788
- if ! v .goEnvVersionFound {
789
- // There is no Go version installed. The version in the `go.mod` file is below the
790
- // supported range. Go versions are generally backwards compatible, so we install the
791
- // minimum supported version.
792
- msg = "The version of Go found in the `go.mod` file (" + v .goModVersion +
793
- ") is below the supported range (" + minGoVersion + "-" + maxGoVersion +
794
- "). No version of Go installed. Writing an environment file specifying the " +
795
- "minimum supported version of Go (" + minGoVersion + ")."
796
- version = minGoVersion
797
- diagnostics .EmitNoGoEnv (msg )
798
- } else if outsideSupportedRange (v .goEnvVersion ) {
799
- // The version of Go that is installed is outside of the supported range. The version
800
- // in the `go.mod` file is below the supported range. Go versions are generally
801
- // backwards compatible, so we install the minimum supported version.
802
- msg = "The version of Go found in the `go.mod` file (" + v .goModVersion +
803
- ") is below the supported range (" + minGoVersion + "-" + maxGoVersion +
804
- "). The version of Go installed in the environment (" + v .goEnvVersion +
805
- ") is outside of the supported range (" + minGoVersion + "-" + maxGoVersion + "). " +
806
- "Writing an environment file specifying the minimum supported version of Go (" +
807
- minGoVersion + ")."
808
- version = minGoVersion
809
- diagnostics .EmitVersionGoModSupportedAndGoEnvUnsupported (msg )
810
- } else {
811
- // The version of Go that is installed is supported. The version in the `go.mod` file is
812
- // below the supported range. We do not install a version of Go.
813
- msg = "The version of Go installed in the environment (" + v .goEnvVersion +
814
- ") is supported and is high enough for the version found in the `go.mod` file (" +
815
- v .goModVersion + "). Writing an environment file not specifying any version of Go."
816
- version = ""
817
- diagnostics .EmitVersionGoModNotHigherVersionEnvironment (msg )
818
- }
822
+ diagnostics .EmitVersionGoModNotHigherVersionEnvironment (msg )
823
+ }
824
+
825
+ return msg , version
826
+ }
827
+
828
+ // Assuming `v.goModVersion` is in the supported range, emit a diagnostic and return the version
829
+ // to install, or the empty string if we should not attempt to install a version of Go.
830
+ func getVersionWhenGoModVersionSupported (v versionInfo ) (msg , version string ) {
831
+ if ! v .goEnvVersionFound {
832
+ // There is no Go version installed. The version in the `go.mod` file is supported.
833
+ // We install the version from the `go.mod` file.
834
+ msg = "No version of Go installed. Writing an environment file specifying the version " +
835
+ "of Go found in the `go.mod` file (" + v .goModVersion + ")."
836
+ version = v .goModVersion
837
+ diagnostics .EmitNoGoEnv (msg )
838
+ } else if outsideSupportedRange (v .goEnvVersion ) {
839
+ // The version of Go that is installed is outside of the supported range. The version in
840
+ // the `go.mod` file is supported. We install the version from the `go.mod` file.
841
+ msg = "The version of Go installed in the environment (" + v .goEnvVersion +
842
+ ") is outside of the supported range (" + minGoVersion + "-" + maxGoVersion + "). " +
843
+ "Writing an environment file specifying the version of Go from the `go.mod` file (" +
844
+ v .goModVersion + ")."
845
+ version = v .goModVersion
846
+ diagnostics .EmitVersionGoModSupportedAndGoEnvUnsupported (msg )
847
+ } else if semver .Compare ("v" + v .goModVersion , "v" + v .goEnvVersion ) > 0 {
848
+ // The version of Go that is installed is supported. The version in the `go.mod` file is
849
+ // supported and is higher than the version that is installed. We install the version from
850
+ // the `go.mod` file.
851
+ msg = "The version of Go installed in the environment (" + v .goEnvVersion +
852
+ ") is lower than the version found in the `go.mod` file (" + v .goModVersion +
853
+ "). Writing an environment file specifying the version of Go from the `go.mod` " +
854
+ "file (" + v .goModVersion + ")."
855
+ version = v .goModVersion
856
+ diagnostics .EmitVersionGoModHigherVersionEnvironment (msg )
819
857
} else {
820
- // v.goModVersion is within the supported range.
821
- if ! v .goEnvVersionFound {
822
- // There is no Go version installed. The version in the `go.mod` file is supported.
823
- // We install the version from the `go.mod` file.
824
- msg = "No version of Go installed. Writing an environment file specifying the version " +
825
- "of Go found in the `go.mod` file (" + v .goModVersion + ")."
826
- version = v .goModVersion
827
- diagnostics .EmitNoGoEnv (msg )
828
- } else if outsideSupportedRange (v .goEnvVersion ) {
829
- // The version of Go that is installed is outside of the supported range. The version in
830
- // the `go.mod` file is supported. We install the version from the `go.mod` file.
831
- msg = "The version of Go installed in the environment (" + v .goEnvVersion +
832
- ") is outside of the supported range (" + minGoVersion + "-" + maxGoVersion + "). " +
833
- "Writing an environment file specifying the version of Go from the `go.mod` file (" +
834
- v .goModVersion + ")."
835
- version = v .goModVersion
836
- diagnostics .EmitVersionGoModSupportedAndGoEnvUnsupported (msg )
837
- } else if semver .Compare ("v" + v .goModVersion , "v" + v .goEnvVersion ) > 0 {
838
- // The version of Go that is installed is supported. The version in the `go.mod` file is
839
- // supported and is higher than the version that is installed. We install the version from
840
- // the `go.mod` file.
841
- msg = "The version of Go installed in the environment (" + v .goEnvVersion +
842
- ") is lower than the version found in the `go.mod` file (" + v .goModVersion +
843
- "). Writing an environment file specifying the version of Go from the `go.mod` " +
844
- "file (" + v .goModVersion + ")."
845
- version = v .goModVersion
846
- diagnostics .EmitVersionGoModHigherVersionEnvironment (msg )
847
- } else {
848
- // The version of Go that is installed is supported. The version in the `go.mod` file is
849
- // supported and is lower than or equal to the version that is installed. We do not install
850
- // a version of Go.
851
- msg = "The version of Go installed in the environment (" + v .goEnvVersion +
852
- ") is supported and is high enough for the version found in the `go.mod` file (" +
853
- v .goModVersion + "). Writing an environment file not specifying any version of Go."
854
- version = ""
855
- diagnostics .EmitVersionGoModNotHigherVersionEnvironment (msg )
856
- }
858
+ // The version of Go that is installed is supported. The version in the `go.mod` file is
859
+ // supported and is lower than or equal to the version that is installed. We do not install
860
+ // a version of Go.
861
+ msg = "The version of Go installed in the environment (" + v .goEnvVersion +
862
+ ") is supported and is high enough for the version found in the `go.mod` file (" +
863
+ v .goModVersion + "). Writing an environment file not specifying any version of Go."
864
+ version = ""
865
+ diagnostics .EmitVersionGoModNotHigherVersionEnvironment (msg )
857
866
}
858
867
859
868
return msg , version
@@ -863,10 +872,18 @@ func checkForGoModVersionFound(v versionInfo) (msg, version string) {
863
872
// version to install. If the version is the empty string then no installation is required.
864
873
func getVersionToInstall (v versionInfo ) (msg , version string ) {
865
874
if ! v .goModVersionFound {
866
- return checkForGoModVersionNotFound (v )
875
+ return getVersionWhenGoModVersionNotFound (v )
876
+ }
877
+
878
+ if aboveSupportedRange (v .goModVersion ) {
879
+ return getVersionWhenGoModVersionTooHigh (v )
880
+ }
881
+
882
+ if belowSupportedRange (v .goModVersion ) {
883
+ return getVersionWhenGoModVersionTooLow (v )
867
884
}
868
885
869
- return checkForGoModVersionFound (v )
886
+ return getVersionWhenGoModVersionSupported (v )
870
887
}
871
888
872
889
// Write an environment file to the current directory. If `version` is the empty string then
0 commit comments