package cmd import ( "fmt" "github.com/zemenawi/zutils/pkg/types" "github.com/zemenawi/zutils/pkg/colors" ) // InfoCommand handles the info command with subcommands func InfoCommand(args []string) error { if len(args) < 1 { printInfoUsage() return fmt.Errorf("missing argument") } target := args[0] switch target { case "file": if len(args) < 2 { return fmt.Errorf("please specify a file path") } return FileInfoCommand(args[1:]) case "dir": if len(args) < 2 { return fmt.Errorf("please specify a directory path") } return DirInfoCommand(args[1:]) case "network": return NetworkInfoCommand([]string{}) default: // Auto-detect: if it's "network", show network info if target == "network" { return NetworkInfoCommand([]string{}) } // Otherwise, it's a path - auto-detect file or directory return AutoDetectInfo(target) } } func printInfoUsage() { fmt.Printf("%sUsage:%s z info \n\n", colors.Cyan, colors.Reset) fmt.Printf("%sExamples:%s\n", colors.Cyan, colors.Reset) fmt.Println(" z info file /path/to/file.txt") fmt.Println(" z info dir /path/to/directory") fmt.Println(" z info network") fmt.Println(" z info /path/to/file.txt # Auto-detect") fmt.Println(" z info /path/to/directory # Auto-detect") } func RegisterInfoCommands(registry *types.CommandRegistry) { registry.Register(&types.Command{ Name: "info", Description: "Get information about files, directories, or network", Handler: InfoCommand, }) } func PrintBoxHeader(title string, colorCode string) { fmt.Printf("\n%s%s╔══════════════════════════════════════╗%s\n", colorCode, colors.Bold, colors.Reset) fmt.Printf("%s%s║%s %-34s %s%s║%s\n", colorCode, colors.Bold, colors.Reset, CenterText(title, 34), colorCode, colors.Bold, colors.Reset) fmt.Printf("%s%s╚══════════════════════════════════════╝%s\n", colorCode, colors.Bold, colors.Reset) fmt.Println() } func CenterText(text string, width int) string { padding := width - len(text) if padding <= 0 { return text[:width] } left := padding / 2 right := padding - left leftPad := "" for i := 0; i < left; i++ { leftPad += " " } rightPad := "" for i := 0; i < right; i++ { rightPad += " " } return leftPad + text + rightPad } func PrintSectionHeader(title string) { fmt.Printf("%s%s───────── %s ─────────%s\n", colors.Gray, colors.Bold, title, colors.Reset) }