package cmd

import (
	"fmt"
	"os"

	"github.com/spf13/cobra"
)

var showCmd = &cobra.Command{
	Use: "show <id>", Short: "Show node details", Args: cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		svc, err := getNodeService()
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			return
		}

		n, err := svc.GetByID(args[0])
		if err != nil {
			fmt.Fprintln(os.Stderr, "node not found:", args[0])
			os.Exit(1)
		}
		PrintNode(cmd.OutOrStdout(), svc, n, jsonFlag)
	},
}

func init() {
	rootCmd.AddCommand(showCmd)
}
