@@ -14,14 +14,6 @@ import (
14
14
"strings"
15
15
)
16
16
17
- type Version struct {
18
- Major string
19
- Minor string
20
- Patch string
21
- Url string
22
- ThreadSafe bool
23
- }
24
-
25
17
func Install (args []string ) {
26
18
if len (args ) < 2 {
27
19
theme .Error ("You must specify a version to install." )
@@ -48,7 +40,7 @@ func Install(args []string) {
48
40
theme .Warning ("Non-thread safe version will be installed" )
49
41
}
50
42
51
- desiredVersionNumbers := common .GetVersion (args [1 ])
43
+ desiredVersionNumbers := common .GetVersion (args [1 ], desireThreadSafe , "" )
52
44
53
45
if desiredVersionNumbers == (common.Version {}) {
54
46
theme .Error ("Invalid version specified" )
@@ -77,7 +69,7 @@ func Install(args []string) {
77
69
re := regexp .MustCompile (`<A HREF="([a-zA-Z0-9./-]+)">([a-zA-Z0-9./-]+)</A>` )
78
70
matches := re .FindAllStringSubmatch (sb , - 1 )
79
71
80
- versions := make ([]Version , 0 )
72
+ versions := make ([]common. Version , 0 )
81
73
82
74
for _ , match := range matches {
83
75
url := match [1 ]
@@ -118,44 +110,31 @@ func Install(args []string) {
118
110
continue
119
111
}
120
112
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 ))
136
115
}
137
116
138
117
// find desired version
139
- var desiredVersion Version
118
+ var desiredVersion common. Version
140
119
141
- if desiredMajorVersion != "" && desiredMinorVersion != "" && desiredPatchVersion != "" {
120
+ if desiredMajorVersion > - 1 && desiredMinorVersion > - 1 && desiredPatchVersion > - 1 {
142
121
desiredVersion = FindExactVersion (versions , desiredMajorVersion , desiredMinorVersion , desiredPatchVersion , desireThreadSafe )
143
122
}
144
123
145
- if desiredMajorVersion != "" && desiredMinorVersion != "" && desiredPatchVersion == "" {
124
+ if desiredMajorVersion > - 1 && desiredMinorVersion > - 1 && desiredPatchVersion == - 1 {
146
125
desiredVersion = FindLatestPatch (versions , desiredMajorVersion , desiredMinorVersion , desireThreadSafe )
147
126
}
148
127
149
- if desiredMajorVersion != "" && desiredMinorVersion == "" && desiredPatchVersion == "" {
128
+ if desiredMajorVersion > - 1 && desiredMinorVersion == - 1 && desiredPatchVersion == - 1 {
150
129
desiredVersion = FindLatestMinor (versions , desiredMajorVersion , desireThreadSafe )
151
130
}
152
131
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 ) )
155
134
return
156
135
}
157
136
158
- fmt .Println ("Installing PHP " + desiredVersion . Major + "." + desiredVersion . Minor + "." + desiredVersion . Patch + " " + threadSafeString )
137
+ fmt .Printf ("Installing PHP %s \n " , desiredVersion )
159
138
160
139
homeDir , err := os .UserHomeDir ()
161
140
@@ -190,7 +169,7 @@ func Install(args []string) {
190
169
191
170
// check if zip already exists
192
171
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 ) )
194
173
return
195
174
}
196
175
@@ -222,7 +201,7 @@ func Install(args []string) {
222
201
log .Fatalln (err )
223
202
}
224
203
225
- theme .Success ("Finished installing PHP " + desiredVersion . Major + "." + desiredVersion . Minor + "." + desiredVersion . Patch + " " + threadSafeString )
204
+ theme .Success (fmt . Sprintf ( "Finished installing PHP %s" , desiredVersion ) )
226
205
}
227
206
228
207
func Unzip (src , dest string ) error {
@@ -289,7 +268,7 @@ func Unzip(src, dest string) error {
289
268
return nil
290
269
}
291
270
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 {
293
272
for _ , version := range versions {
294
273
if version .ThreadSafe != threadSafe {
295
274
continue
@@ -299,18 +278,18 @@ func FindExactVersion(versions []Version, major string, minor string, patch stri
299
278
}
300
279
}
301
280
302
- return Version {}
281
+ return common. Version {}
303
282
}
304
283
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 {}
307
286
308
287
for _ , version := range versions {
309
288
if version .ThreadSafe != threadSafe {
310
289
continue
311
290
}
312
291
if version .Major == major && version .Minor == minor {
313
- if latestPatch .Patch == "" || version .Patch > latestPatch .Patch {
292
+ if latestPatch .Patch == - 1 || version .Patch > latestPatch .Patch {
314
293
latestPatch = version
315
294
}
316
295
}
@@ -319,16 +298,16 @@ func FindLatestPatch(versions []Version, major string, minor string, threadSafe
319
298
return latestPatch
320
299
}
321
300
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 {}
324
303
325
304
for _ , version := range versions {
326
305
if version .ThreadSafe != threadSafe {
327
306
continue
328
307
}
329
308
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 {
332
311
latestMinor = version
333
312
}
334
313
}
0 commit comments