Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit c4e021c

Browse files
Natalie ArellanoCharlie Vieth
authored andcommitted
Allow 3 digit versions
[#148935305](https://www.pivotaltracker.com/story/show/148935305) Signed-off-by: Charlie Vieth <cviethjr@pivotal.io>
1 parent 02aca20 commit c4e021c

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

main.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ Examples:
6666
Will create a stemcell using [vmdk] 'disk.vmdk' with version 1.2 in the current
6767
working directory.
6868
69-
%[1]s -vhd disk.vhd -delta patch.file -v 1.2
69+
%[1]s -vhd disk.vhd -delta patch.file -v 1.2.3
7070
7171
Will create a stemcell using [vhd] 'disk.vhd' and a patch file with
72-
version 1.2 in the current working directory.
72+
version 1.2.3 in the current working directory.
7373
7474
%[1]s -vhd disk.vhd -delta patch.file -gzip -v 1.2 -output foo
7575
@@ -210,12 +210,20 @@ func validateVersion(s string) error {
210210
if s == "" {
211211
return errors.New("missing required argument 'version'")
212212
}
213-
const pattern = `^\d{1,}.\d{1,}$`
214-
if !regexp.MustCompile(pattern).MatchString(s) {
215-
Debugf("expected version string to match regex: '%s'", pattern)
216-
return fmt.Errorf("invalid version (%s) expected format [NUMBER].[NUMBER]", s)
213+
patterns := []string{
214+
`^\d{1,}\.\d{1,}$`,
215+
`^\d{1,}\.\d{1,}-build\.\d{1,}$`,
216+
`^\d{1,}\.\d{1,}\.\d{1,}$`,
217+
`^\d{1,}\.\d{1,}\.\d{1,}-build\.\d{1,}$`,
217218
}
218-
return nil
219+
for _, pattern := range patterns {
220+
if regexp.MustCompile(pattern).MatchString(s) {
221+
return nil
222+
}
223+
}
224+
Debugf("expected version string to match any of the regexes: %s", patterns)
225+
return fmt.Errorf("invalid version (%s) expected format [NUMBER].[NUMBER] or "+
226+
"[NUMBER].[NUMBER].[NUMBER]", s)
219227
}
220228

221229
func StemcellFilename(version, os string) string {

main_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ var versionTests = []struct {
4242
{"a1.2", false},
4343
{"a.2", false},
4444
{"1.2 a", false},
45+
{"1200.0.3-build.2", true},
46+
{"1200.0.3-build.a", false},
47+
{"1.2-build.1", true},
4548
}
4649

4750
func TestValidateVersion(t *testing.T) {

0 commit comments

Comments
 (0)