//go:build linux || freebsd // +build linux freebsd package cli import ( _ "embed" "fmt" "io" "os" "strings" ) //go:embed help.txt var helpText string // ANSI color codes const ( ColorReset = "\033[0m" ColorGreen = "\033[32m" ColorCyan = "\033[36m" ColorYellow = "\033[33m" ColorBlue = "\033[34m" ColorRed = "\033[31m" ColorBold = "\033[1m" ColorMagenta = "\033[35m" ) // isColorTerminal checks if writer supports ANSI colors func isColorTerminal(w io.Writer) bool { if os.Getenv("NO_COLOR") != "" { return false } if _, ok := w.(*os.File); ok { return os.Getenv("TERM") != "dumb" } return false } // PrintUsage prints formatted help from embedded help.txt func PrintUsage(w io.Writer) { useColors := isColorTerminal(w) if useColors { bold := ColorBold reset := ColorReset green := ColorGreen yellow := ColorYellow magenta := ColorMagenta _ = bold _ = reset _ = green _ = yellow _ = magenta // Print help text with ANSI colors for section headers for _, line := range strings.Split(helpText, "\n") { if strings.HasPrefix(line, "NAME") || strings.HasPrefix(line, "SYNOPSIS") || strings.HasPrefix(line, "DESCRIPTION") || strings.HasSuffix(strings.TrimRight(line, " "), ":") { fmt.Fprintf(w, "%s%s%s\n", ColorBold, line, ColorReset) } else { fmt.Fprintln(w, line) } } } else { fmt.Fprint(w, helpText) } } // PrintCategoryHelp prints help filtered by category. // Categories: all, target, network, auth, mirror, recursive, verify, queue, metalink, upload, pgp, extraction, config func PrintCategoryHelp(w io.Writer, category string) { if category == "" || category == "all" { PrintUsage(w) return } categories := map[string]string{ "target": "TARGETS", "network": "NETWORK", "auth": "AUTHENTICATION", "mirror": "MIRROR MODE", "recursive": "RECURSIVE DOWNLOAD", "verify": "VERIFICATION", "queue": "DOWNLOAD QUEUE", "metalink": "METALINK", "upload": "BASIC OPTIONS", "pgp": "PGP/GPG", "extraction": "EXTRACTION", "config": "CONFIGURATION", } title, ok := categories[strings.ToLower(category)] if !ok { fmt.Fprintf(w, "Unknown category: %s\nAvailable: %s\n", category, "target, network, auth, mirror, recursive, verify, queue, metalink, upload, pgp, extraction, config, all") return } fmt.Fprintf(w, "Showing category: %s\nUse --help for full help.\n\n", title) PrintUsage(w) // For now, print full help — future: filter }