@@ -14,14 +14,6 @@ import (
1414 "strings"
1515)
1616
17- type Version struct {
18- Major string
19- Minor string
20- Patch string
21- Url string
22- ThreadSafe bool
23- }
24-
2517func Install (args []string ) {
2618 if len (args ) < 2 {
2719 theme .Error ("You must specify a version to install." )
@@ -48,7 +40,7 @@ func Install(args []string) {
4840 theme .Warning ("Non-thread safe version will be installed" )
4941 }
5042
51- desiredVersionNumbers := common .GetVersion (args [1 ])
43+ desiredVersionNumbers := common .GetVersion (args [1 ], desireThreadSafe , "" )
5244
5345 if desiredVersionNumbers == (common.Version {}) {
5446 theme .Error ("Invalid version specified" )
@@ -77,7 +69,7 @@ func Install(args []string) {
7769 re := regexp .MustCompile (`<A HREF="([a-zA-Z0-9./-]+)">([a-zA-Z0-9./-]+)</A>` )
7870 matches := re .FindAllStringSubmatch (sb , - 1 )
7971
80- versions := make ([]Version , 0 )
72+ versions := make ([]common. Version , 0 )
8173
8274 for _ , match := range matches {
8375 url := match [1 ]
@@ -118,44 +110,31 @@ func Install(args []string) {
118110 continue
119111 }
120112
121- // regex match name
122- versionNumbers := common .GetVersion (name )
123-
124- major := versionNumbers .Major
125- minor := versionNumbers .Minor
126- patch := versionNumbers .Patch
127-
128- // push to versions
129- versions = append (versions , Version {
130- Major : major ,
131- Minor : minor ,
132- Patch : patch ,
133- Url : url ,
134- ThreadSafe : threadSafe ,
135- })
113+ // regex match name and push to versions
114+ versions = append (versions , common .GetVersion (name , threadSafe , url ))
136115 }
137116
138117 // find desired version
139- var desiredVersion Version
118+ var desiredVersion common. Version
140119
141- if desiredMajorVersion != "" && desiredMinorVersion != "" && desiredPatchVersion != "" {
120+ if desiredMajorVersion > - 1 && desiredMinorVersion > - 1 && desiredPatchVersion > - 1 {
142121 desiredVersion = FindExactVersion (versions , desiredMajorVersion , desiredMinorVersion , desiredPatchVersion , desireThreadSafe )
143122 }
144123
145- if desiredMajorVersion != "" && desiredMinorVersion != "" && desiredPatchVersion == "" {
124+ if desiredMajorVersion > - 1 && desiredMinorVersion > - 1 && desiredPatchVersion == - 1 {
146125 desiredVersion = FindLatestPatch (versions , desiredMajorVersion , desiredMinorVersion , desireThreadSafe )
147126 }
148127
149- if desiredMajorVersion != "" && desiredMinorVersion == "" && desiredPatchVersion == "" {
128+ if desiredMajorVersion > - 1 && desiredMinorVersion == - 1 && desiredPatchVersion == - 1 {
150129 desiredVersion = FindLatestMinor (versions , desiredMajorVersion , desireThreadSafe )
151130 }
152131
153- if desiredVersion == (Version {}) {
154- theme .Error ("Could not find the desired version: " + args [1 ] + " " + threadSafeString )
132+ if desiredVersion == (common. Version {}) {
133+ theme .Error (fmt . Sprintf ( "Could not find the desired version: %s %s" , args [1 ], threadSafeString ) )
155134 return
156135 }
157136
158- fmt .Println ("Installing PHP " + desiredVersion . Major + "." + desiredVersion . Minor + "." + desiredVersion . Patch + " " + threadSafeString )
137+ fmt .Printf ("Installing PHP %s \n " , desiredVersion )
159138
160139 homeDir , err := os .UserHomeDir ()
161140
@@ -190,7 +169,7 @@ func Install(args []string) {
190169
191170 // check if zip already exists
192171 if _ , err := os .Stat (homeDir + "/.pvm/versions/" + zipFileName ); err == nil {
193- theme .Error ("PHP " + desiredVersion . Major + "." + desiredVersion . Minor + "." + desiredVersion . Patch + " " + threadSafeString + " already exists" )
172+ theme .Error (fmt . Sprintf ( "PHP %s already exists" , desiredVersion ) )
194173 return
195174 }
196175
@@ -222,7 +201,7 @@ func Install(args []string) {
222201 log .Fatalln (err )
223202 }
224203
225- theme .Success ("Finished installing PHP " + desiredVersion . Major + "." + desiredVersion . Minor + "." + desiredVersion . Patch + " " + threadSafeString )
204+ theme .Success (fmt . Sprintf ( "Finished installing PHP %s" , desiredVersion ) )
226205}
227206
228207func Unzip (src , dest string ) error {
@@ -289,7 +268,7 @@ func Unzip(src, dest string) error {
289268 return nil
290269}
291270
292- func FindExactVersion (versions []Version , major string , minor string , patch string , threadSafe bool ) Version {
271+ func FindExactVersion (versions []common. Version , major int , minor int , patch int , threadSafe bool ) common. Version {
293272 for _ , version := range versions {
294273 if version .ThreadSafe != threadSafe {
295274 continue
@@ -299,18 +278,18 @@ func FindExactVersion(versions []Version, major string, minor string, patch stri
299278 }
300279 }
301280
302- return Version {}
281+ return common. Version {}
303282}
304283
305- func FindLatestPatch (versions []Version , major string , minor string , threadSafe bool ) Version {
306- latestPatch := Version {}
284+ func FindLatestPatch (versions []common. Version , major int , minor int , threadSafe bool ) common. Version {
285+ latestPatch := common. Version {}
307286
308287 for _ , version := range versions {
309288 if version .ThreadSafe != threadSafe {
310289 continue
311290 }
312291 if version .Major == major && version .Minor == minor {
313- if latestPatch .Patch == "" || version .Patch > latestPatch .Patch {
292+ if latestPatch .Patch == - 1 || version .Patch > latestPatch .Patch {
314293 latestPatch = version
315294 }
316295 }
@@ -319,16 +298,16 @@ func FindLatestPatch(versions []Version, major string, minor string, threadSafe
319298 return latestPatch
320299}
321300
322- func FindLatestMinor (versions []Version , major string , threadSafe bool ) Version {
323- latestMinor := Version {}
301+ func FindLatestMinor (versions []common. Version , major int , threadSafe bool ) common. Version {
302+ latestMinor := common. Version {}
324303
325304 for _ , version := range versions {
326305 if version .ThreadSafe != threadSafe {
327306 continue
328307 }
329308 if version .Major == major {
330- if latestMinor .Minor == "" || version .Minor > latestMinor .Minor {
331- if latestMinor .Patch == "" || version .Patch > latestMinor .Patch {
309+ if latestMinor .Minor == - 1 || version .Minor > latestMinor .Minor {
310+ if latestMinor .Patch == - 1 || version .Patch > latestMinor .Patch {
332311 latestMinor = version
333312 }
334313 }
0 commit comments