Use go regex

Resolves #9
This commit is contained in:
dump_stack() 2019-12-29 07:24:59 +00:00
parent 959e6e6596
commit 6a54439180
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC

View File

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