linsk/cmd/run.go

45 lines
956 B
Go
Raw Normal View History

2023-08-25 16:54:58 +01:00
package cmd
import (
"context"
"fmt"
"log/slog"
2023-08-26 09:16:52 +01:00
"github.com/AlexSSD7/linsk/vm"
2023-08-25 16:54:58 +01:00
"github.com/spf13/cobra"
)
var runCmd = &cobra.Command{
Use: "run",
// TODO: Fill this
// Short: "",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
vmMountDevName := args[1]
fsType := args[2]
2023-08-25 19:55:11 +01:00
// TODO: `slog` library prints entire stack traces for errors which makes reading errors challenging.
2023-08-25 16:54:58 +01:00
runVM(args[0], func(ctx context.Context, i *vm.Instance, fm *vm.FileManager) {
2023-08-25 19:55:11 +01:00
err := fm.Mount(vmMountDevName, vm.MountOptions{
FSType: fsType,
LUKS: luksFlag,
})
2023-08-25 16:54:58 +01:00
if err != nil {
slog.Error("Failed to mount the disk inside the VM", "error", err)
return
}
fmt.Println("Mounted! Now sleeping")
<-ctx.Done()
})
return nil
},
}
2023-08-25 19:55:11 +01:00
var luksFlag bool
func init() {
runCmd.Flags().BoolVarP(&luksFlag, "luks", "l", false, "Use cryptsetup to open a LUKS volume (password will be prompted)")
}