package cli import ( "fmt" "os" "path/filepath" "text/tabwriter" "github.com/spf13/cobra" ) var runtimeCmd = &cobra.Command{ Use: "runtime", Short: "Manage runtime configurations", } var runtimeListCmd = &cobra.Command{ Use: "list", Short: "List available runtimes", RunE: runRuntimeList, } func init() { runtimeCmd.AddCommand(runtimeListCmd) } func runRuntimeList(cmd *cobra.Command, args []string) error { dir := configDir() runtimesDir := filepath.Join(dir, "runtimes") imagesDir := filepath.Join(dir, "images") entries, err := os.ReadDir(runtimesDir) if err != nil { if os.IsNotExist(err) { fmt.Println("No runtimes configured. Run 'at-rund init' first.") return nil } return err } w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) fmt.Fprintln(w, "RUNTIME\tCONFIG\tIMAGE\tSTATUS") for _, e := range entries { if filepath.Ext(e.Name()) != ".nix" { continue } name := e.Name()[:len(e.Name())-4] configPath := filepath.Join(runtimesDir, e.Name()) imagePath := filepath.Join(imagesDir, name) status := "not built" if _, err := os.Stat(filepath.Join(imagePath, "rootfs.ext4")); err == nil { status = "ready" } else if _, err := os.Stat(imagePath); err == nil { status = "partial" } fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", name, configPath, imagePath, status) } w.Flush() return nil }