builder/qemu: allow to specify time.Duration in special <wait> command
Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
parent
c1ac120828
commit
2104fcec69
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
|
@ -154,6 +155,19 @@ func vncSendString(c *vnc.ClientConn, original string) {
|
|||
continue
|
||||
}
|
||||
|
||||
if strings.HasPrefix(original, "<wait") && strings.HasSuffix(original, ">") {
|
||||
re := regexp.MustCompile(`<wait([0-9hms]+)>$`)
|
||||
dstr := re.FindStringSubmatch(original)
|
||||
if len(dstr) > 1 {
|
||||
log.Printf("Special code %s found, sleeping", dstr[0])
|
||||
if dt, err := time.ParseDuration(dstr[1]); err == nil {
|
||||
time.Sleep(dt)
|
||||
original = original[len(dstr[0]):]
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for specialCode, specialValue := range special {
|
||||
if strings.HasPrefix(original, specialCode) {
|
||||
log.Printf("Special code '%s' found, replacing with: %d", specialCode, specialValue)
|
||||
|
|
|
@ -310,6 +310,9 @@ by the proper key:
|
|||
sending any additional keys. This is useful if you have to generally wait
|
||||
for the UI to update before typing more.
|
||||
|
||||
- `<waitXX> ` - Add user defined time.Duration pause before sending any
|
||||
additional keys. For example `<wait10m>` or `<wait1m20s>`
|
||||
|
||||
In addition to the special keys, each command to type is treated as a
|
||||
[configuration template](/docs/templates/configuration-templates.html). The
|
||||
available variables are:
|
||||
|
|
Loading…
Reference in New Issue