Implement shell command
This commit is contained in:
parent
dc67d021e1
commit
702f06e914
6 changed files with 134 additions and 12 deletions
14
cmd/utils.go
14
cmd/utils.go
|
|
@ -35,13 +35,17 @@ func doRootCheck() {
|
|||
}
|
||||
}
|
||||
|
||||
func runVM(passthroughArg string, fn func(context.Context, *vm.Instance, *vm.FileManager)) *vm.Instance {
|
||||
func runVM(passthroughArg string, fn func(context.Context, *vm.Instance, *vm.FileManager) int) int {
|
||||
doRootCheck()
|
||||
|
||||
passthroughConfig := getDevicePassthroughConfig(passthroughArg)
|
||||
var passthroughConfig []vm.USBDevicePassthroughConfig
|
||||
|
||||
if passthroughArg != "" {
|
||||
passthroughConfig = []vm.USBDevicePassthroughConfig{getDevicePassthroughConfig(passthroughArg)}
|
||||
}
|
||||
|
||||
// TODO: Alpine image should be downloaded from somewhere.
|
||||
vi, err := vm.NewInstance(slog.Default().With("caller", "vm"), "alpine-img/alpine.qcow2", []vm.USBDevicePassthroughConfig{passthroughConfig}, true)
|
||||
vi, err := vm.NewInstance(slog.Default().With("caller", "vm"), "alpine-img/alpine.qcow2", passthroughConfig, vmDebugFlag)
|
||||
if err != nil {
|
||||
slog.Error("Failed to create vm instance", "error", err)
|
||||
os.Exit(1)
|
||||
|
|
@ -104,7 +108,7 @@ func runVM(passthroughArg string, fn func(context.Context, *vm.Instance, *vm.Fil
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
fn(ctx, vi, fm)
|
||||
exitCode := fn(ctx, vi, fm)
|
||||
|
||||
err = vi.Cancel()
|
||||
if err != nil {
|
||||
|
|
@ -123,7 +127,7 @@ func runVM(passthroughArg string, fn func(context.Context, *vm.Instance, *vm.Fil
|
|||
default:
|
||||
}
|
||||
|
||||
return nil
|
||||
return exitCode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue