Custom name for generate VMs

This commit is contained in:
Mikhail Klementev 2019-12-30 13:58:18 +00:00
parent cc92ec3e23
commit 9c6b8a0122
No known key found for this signature in database
GPG Key ID: BE44DA8C062D87DC
2 changed files with 10 additions and 3 deletions

View File

@ -403,12 +403,13 @@ func main() {
generateCommand := kingpin.Command("generate", "Generate appvm definition") generateCommand := kingpin.Command("generate", "Generate appvm definition")
generateName := generateCommand.Arg("name", "Nix package name").Required().String() generateName := generateCommand.Arg("name", "Nix package name").Required().String()
generateBin := generateCommand.Arg("bin", "Binary").Default("").String() generateBin := generateCommand.Arg("bin", "Binary").Default("").String()
generateVMName := generateCommand.Flag("vm", "Use VM Name").Default("").String()
switch kingpin.Parse() { switch kingpin.Parse() {
case "list": case "list":
list(l) list(l)
case "generate": case "generate":
generate(l, *generateName, *generateBin) generate(l, *generateName, *generateBin, *generateVMName)
case "start": case "start":
start(l, *startName, *startVerbose) start(l, *startName, *startVerbose)
case "stop": case "stop":

View File

@ -42,7 +42,7 @@ func nixPath(name string) (path string, err error) {
return return
} }
func generate(l *libvirt.Libvirt, name, bin string) { func generate(l *libvirt.Libvirt, name, bin, vmname string) {
if !isPackageExists(name) { if !isPackageExists(name) {
log.Println("Package pkgs."+name, "does not exists") log.Println("Package pkgs."+name, "does not exists")
return return
@ -88,7 +88,13 @@ func generate(l *libvirt.Libvirt, name, bin string) {
} }
realName := strings.Split(name, ".")[1] realName := strings.Split(name, ".")[1]
appFilename := configDir + "/nix/" + realName + ".nix"
var appFilename string
if vmname != "" {
appFilename = configDir + "/nix/" + vmname + ".nix"
} else {
appFilename = configDir + "/nix/" + realName + ".nix"
}
appNixConfig := fmt.Sprintf(template, realName, bin) appNixConfig := fmt.Sprintf(template, realName, bin)