@@ -15,9 +15,9 @@ import (
1515)
1616
1717type Version struct {
18- Major string
19- Minor string
20- Patch string
18+ Major int
19+ Minor int
20+ Patch int
2121 Url string
2222 ThreadSafe bool
2323}
@@ -138,24 +138,24 @@ func Install(args []string) {
138138 // find desired version
139139 var desiredVersion Version
140140
141- if desiredMajorVersion != "" && desiredMinorVersion != "" && desiredPatchVersion != "" {
141+ if desiredMajorVersion > - 1 && desiredMinorVersion > - 1 && desiredPatchVersion > - 1 {
142142 desiredVersion = FindExactVersion (versions , desiredMajorVersion , desiredMinorVersion , desiredPatchVersion , desireThreadSafe )
143143 }
144144
145- if desiredMajorVersion != "" && desiredMinorVersion != "" && desiredPatchVersion == "" {
145+ if desiredMajorVersion > - 1 && desiredMinorVersion > - 1 && desiredPatchVersion == - 1 {
146146 desiredVersion = FindLatestPatch (versions , desiredMajorVersion , desiredMinorVersion , desireThreadSafe )
147147 }
148148
149- if desiredMajorVersion != "" && desiredMinorVersion == "" && desiredPatchVersion == "" {
149+ if desiredMajorVersion > - 1 && desiredMinorVersion == - 1 && desiredPatchVersion == - 1 {
150150 desiredVersion = FindLatestMinor (versions , desiredMajorVersion , desireThreadSafe )
151151 }
152152
153153 if desiredVersion == (Version {}) {
154- theme .Error ("Could not find the desired version: " + args [1 ] + " " + threadSafeString )
154+ theme .Error (fmt . Sprintf ( "Could not find the desired version: %s %s" , args [1 ], threadSafeString ) )
155155 return
156156 }
157157
158- fmt .Println ("Installing PHP " + desiredVersion .Major + "." + desiredVersion .Minor + "." + desiredVersion .Patch + " " + threadSafeString )
158+ fmt .Printf ("Installing PHP %d.%d.%d %s \n " , desiredVersion .Major , desiredVersion .Minor , desiredVersion .Patch , threadSafeString )
159159
160160 homeDir , err := os .UserHomeDir ()
161161
@@ -190,7 +190,7 @@ func Install(args []string) {
190190
191191 // check if zip already exists
192192 if _ , err := os .Stat (homeDir + "/.pvm/versions/" + zipFileName ); err == nil {
193- theme .Error ("PHP " + desiredVersion .Major + "." + desiredVersion .Minor + "." + desiredVersion .Patch + " " + threadSafeString + " already exists" )
193+ theme .Error (fmt . Sprintf ( "PHP %d.%d.%d %s already exists" , desiredVersion .Major , desiredVersion .Minor , desiredVersion .Patch , threadSafeString ) )
194194 return
195195 }
196196
@@ -222,7 +222,7 @@ func Install(args []string) {
222222 log .Fatalln (err )
223223 }
224224
225- theme .Success ("Finished installing PHP " + desiredVersion .Major + "." + desiredVersion .Minor + "." + desiredVersion .Patch + " " + threadSafeString )
225+ theme .Success (fmt . Sprintf ( "Finished installing PHP %d.%d.%d %s" , desiredVersion .Major , desiredVersion .Minor , desiredVersion .Patch , threadSafeString ) )
226226}
227227
228228func Unzip (src , dest string ) error {
@@ -289,7 +289,7 @@ func Unzip(src, dest string) error {
289289 return nil
290290}
291291
292- func FindExactVersion (versions []Version , major string , minor string , patch string , threadSafe bool ) Version {
292+ func FindExactVersion (versions []Version , major int , minor int , patch int , threadSafe bool ) Version {
293293 for _ , version := range versions {
294294 if version .ThreadSafe != threadSafe {
295295 continue
@@ -302,15 +302,15 @@ func FindExactVersion(versions []Version, major string, minor string, patch stri
302302 return Version {}
303303}
304304
305- func FindLatestPatch (versions []Version , major string , minor string , threadSafe bool ) Version {
305+ func FindLatestPatch (versions []Version , major int , minor int , threadSafe bool ) Version {
306306 latestPatch := Version {}
307307
308308 for _ , version := range versions {
309309 if version .ThreadSafe != threadSafe {
310310 continue
311311 }
312312 if version .Major == major && version .Minor == minor {
313- if latestPatch .Patch == "" || version .Patch > latestPatch .Patch {
313+ if latestPatch .Patch == - 1 || version .Patch > latestPatch .Patch {
314314 latestPatch = version
315315 }
316316 }
@@ -319,16 +319,16 @@ func FindLatestPatch(versions []Version, major string, minor string, threadSafe
319319 return latestPatch
320320}
321321
322- func FindLatestMinor (versions []Version , major string , threadSafe bool ) Version {
322+ func FindLatestMinor (versions []Version , major int , threadSafe bool ) Version {
323323 latestMinor := Version {}
324324
325325 for _ , version := range versions {
326326 if version .ThreadSafe != threadSafe {
327327 continue
328328 }
329329 if version .Major == major {
330- if latestMinor .Minor == "" || version .Minor > latestMinor .Minor {
331- if latestMinor .Patch == "" || version .Patch > latestMinor .Patch {
330+ if latestMinor .Minor == - 1 || version .Minor > latestMinor .Minor {
331+ if latestMinor .Patch == - 1 || version .Patch > latestMinor .Patch {
332332 latestMinor = version
333333 }
334334 }
0 commit comments