package main import ( "fmt" "os" "github.com/zemenawi/zutils/cmd" "github.com/zemenawi/zutils/pkg/types" ) func main() { registry := types.NewCommandRegistry() // Register all commands cmd.RegisterInfoCommands(registry) registry.Register(&types.Command{ Name: "version", Description: "Show version information", Handler: cmd.VersionCommand, }) // Parse command line arguments args := os.Args[1:] if len(args) == 0 { printUsage(registry) os.Exit(1) } // Handle legacy 'info' subcommand pattern for backwards compatibility if args[0] == "info" { infoCmd, exists := registry.Get("info") if !exists { printUsage(registry) os.Exit(1) } err := infoCmd.Handler(args[1:]) if err != nil { fmt.Printf("Error: %v\n", err) os.Exit(1) } return } // Direct command: z info commandName := args[0] cmdArgs := args[1:] if command, exists := registry.Get(commandName); exists { err := command.Handler(cmdArgs) if err != nil { fmt.Printf("Error: %v\n", err) os.Exit(1) } } else { // If no command matches, try auto-detect as info command err := cmd.InfoCommand(args) if err != nil { fmt.Printf("Error: %v\n", err) printUsage(registry) os.Exit(1) } } } func printUsage(registry *types.CommandRegistry) { fmt.Println("z - User-friendly terminal utilities") fmt.Println() fmt.Println("Usage: z [arguments]") fmt.Println() fmt.Println("Commands:") for _, command := range registry.GetAll() { fmt.Printf(" %-12s %s\n", command.Name, command.Description) } fmt.Println() fmt.Println("Quick Examples:") fmt.Println(" z info main.go # File information") fmt.Println(" z info . # Directory information") fmt.Println(" z info network # Network information") fmt.Println(" z main.go # Auto-detect file info") fmt.Println() }