Skip to content

Commit c57b3a5

Browse files
kamyninavania-pooh
authored andcommitted
Using [0X-XX] in hostname pattern (#6)
Support hostnames contains 01:10
1 parent fd2f45f commit c57b3a5

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

cmd/generate.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,14 @@ func parseHostPattern(pattern string) []string {
185185
from, _ := strconv.Atoi(pieces[2])
186186
to, _ := strconv.Atoi(pieces[3])
187187
tail := pieces[4]
188+
hostnameFmt := fmt.Sprintf("%%s%%0%dd%%s", len(pieces[2]))
188189
if from <= to {
189190
ret := []string{}
190191
for i := from; i <= to; i++ {
191-
ret = append(ret, fmt.Sprintf("%s%d%s", head, i, tail))
192+
ret = append(ret, fmt.Sprintf(hostnameFmt, head, i, tail))
192193
}
193194
return ret
194195
}
195196
}
196197
return []string{pattern}
197-
}
198+
}

cmd/generate_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func TestParseHostPattern(t *testing.T) {
1818
AssertThat(t, parseHostPattern("test[1:3]-host"), EqualTo{[]string{"test1-host", "test2-host", "test3-host"}})
1919
AssertThat(t, parseHostPattern("[1:3]-host"), EqualTo{[]string{"1-host", "2-host", "3-host"}})
2020
AssertThat(t, parseHostPattern("host-[1:3]"), EqualTo{[]string{"host-1", "host-2", "host-3"}})
21+
AssertThat(t, parseHostPattern("host-[01:03]"), EqualTo{[]string{"host-01", "host-02", "host-03"}})
2122
}
2223

2324
func TestConvert(t *testing.T) {

0 commit comments

Comments
 (0)