package main

import (
	"fmt"

	"github.com/spf13/cobra"
)

func statusCommand() *cobra.Command {
	return &cobra.Command{
		Use:   "status <node>",
		Short: "Show container status on a node",
		Args:  cobra.ExactArgs(1),
		RunE: func(cmd *cobra.Command, args []string) error {
			cfg, err := loadCfg()
			if err != nil {
				return err
			}

			node, err := cfg.FindNode(args[0])
			if err != nil {
				return err
			}

			host := node.Host
			if node.User != "" {
				host = node.User + "@" + node.Host
			}

			fmt.Printf("Containers on %s (%s):\n\n", args[0], node.Host)
			return sshRun(host, "podman ps --format 'table {{.Names}}\t{{.Status}}\t{{.Image}}'")
		},
	}
}
