Use go regex

Resolves #9
This commit is contained in:
Mikhail Klementev 2019-12-29 07:24:59 +00:00
parent 959e6e6596
commit 6a54439180
No known key found for this signature in database
GPG key ID: BE44DA8C062D87DC

View file

@ -17,6 +17,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
"syscall"
@ -206,12 +207,19 @@ func generateVM(name string, verbose bool) (realpath, reginfo, qcow2 string, err
return
}
// TODO: Use go regex
reginfo, _, _, err = system.System("sh", "-c", "cat result/bin/run-nixos-vm | grep -o 'regInfo=.*/registration'")
bytes, err := ioutil.ReadFile("result/bin/run-nixos-vm")
if err != nil {
return
}
match := regexp.MustCompile("regInfo=.*/registration").FindSubmatch(bytes)
if len(match) != 1 {
err = errors.New("should be one reginfo")
return
}
reginfo = string(match[0])
syscall.Unlink("result")
qcow2 = os.Getenv("HOME") + "/appvm/.fake.qcow2"