linsk/cmd/root.go

75 lines
2.9 KiB
Go
Raw Normal View History

2023-08-25 15:12:19 +01:00
package cmd
import (
2023-09-01 12:40:13 +01:00
"fmt"
2023-08-25 15:12:19 +01:00
"os"
2023-08-30 09:19:02 +01:00
"path/filepath"
"runtime"
2023-08-25 15:12:19 +01:00
2023-08-25 16:54:58 +01:00
"log/slog"
2023-08-25 15:12:19 +01:00
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
2023-08-29 10:37:52 +01:00
Use: "linsk",
Short: "Access Linux-native file system infrastructure (including LVM and LUKS) on macOS and Linux. Powered by a lightweight Alpine Linux VM and FTP.",
Long: `Linsk is a utility that allows you to access Linux-native file system infrastructure, including device mapping technologies like LVM and LUKS without compromise on other operating systems that have little ` +
`to no support for Linux's wide range of file systems, mainly aiming macOS and Windows. Linsk does not reimplement any file system. Instead, Linsk ` +
`utilizes a lightweight Alpine Linux VM to tap into the native Linux software ecosystem. The files are then exposed to the host via fast and widely-supported FTP, ` +
`operating at near-hardware speeds.`,
2023-08-25 15:12:19 +01:00
}
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
2023-09-01 12:40:13 +01:00
var (
vmDebugFlag bool
unrestrictedNetworkingFlag bool
vmMemAllocFlag uint32
vmSSHSetupTimeoutFlag uint32
vmOSUpTimeoutFlag uint32
dataDirFlag string
)
const (
defaultMemAlloc = 512
defaultMemAllocLUKS = 2048
)
2023-08-29 10:59:50 +01:00
2023-08-25 15:12:19 +01:00
func init() {
2023-08-25 16:54:58 +01:00
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, nil)))
2023-08-25 15:12:19 +01:00
rootCmd.AddCommand(lsCmd)
2023-08-25 16:54:58 +01:00
rootCmd.AddCommand(runCmd)
2023-08-26 11:27:38 +01:00
rootCmd.AddCommand(shellCmd)
2023-08-30 09:43:41 +01:00
rootCmd.AddCommand(cleanCmd)
2023-08-30 12:39:38 +01:00
rootCmd.AddCommand(buildCmd)
2023-08-30 14:53:22 +01:00
rootCmd.AddCommand(versionCmd)
2023-08-26 11:27:38 +01:00
2023-08-30 13:38:34 +01:00
rootCmd.PersistentFlags().BoolVar(&vmDebugFlag, "vm-debug", false, "Enables the VM debug mode. This will open an accessible VM monitor. You can log in with root user and no password.")
rootCmd.PersistentFlags().BoolVar(&unrestrictedNetworkingFlag, "vm-unrestricted-networking", false, "Enables unrestricted networking. This will allow the VM to connect to the internet.")
2023-09-01 12:40:13 +01:00
rootCmd.PersistentFlags().Uint32Var(&vmMemAllocFlag, "vm-mem-alloc", defaultMemAlloc, fmt.Sprintf("Specifies the VM memory allocation in KiB (the default is %v in LUKS mode)", defaultMemAllocLUKS))
2023-08-29 11:51:06 +01:00
rootCmd.PersistentFlags().Uint32Var(&vmOSUpTimeoutFlag, "vm-os-up-timeout", 30, "Specifies the VM OS-up timeout in seconds.")
rootCmd.PersistentFlags().Uint32Var(&vmSSHSetupTimeoutFlag, "vm-ssh-setup-timeout", 60, "Specifies the VM SSH server setup timeout in seconds. This cannot be lower than the OS-up timeout.")
2023-08-30 09:19:02 +01:00
defaultDataDir := "linsk-data-dir"
homeDir, err := os.UserHomeDir()
if err != nil {
slog.Error("Failed to get user home directory, will use a local directory as a fallback", "error", err.Error(), "dir", defaultDataDir)
} else {
homeDirName := ".linsk"
if runtime.GOOS == "windows" {
homeDirName = "Linsk"
}
defaultDataDir = filepath.Join(homeDir, homeDirName)
}
2023-08-30 15:24:25 +01:00
rootCmd.PersistentFlags().StringVarP(&dataDirFlag, "data-dir", "d", defaultDataDir, "Specifies the data directory (folder) to use. VM images and related work files will be stored here.")
2023-08-25 15:12:19 +01:00
}