package main import ( "bufio" "flag" "fmt" "os" "rubric/catalog" "rubric/modules/devopsmodules" "rubric/modules/gomodules" "rubric/modules/infosecmodules" "rubric/modules/linuxmodules" "rubric/utils" "strings" ) func main() { book := flag.String("book", "", "открыть справочник (go, linux, devops, infosec)") topic := flag.String("topic", "", "открыть раздел (используется вместе с -book)") search := flag.String("search", "", "поиск по всем справочникам") list := flag.Bool("list", false, "список всех справочников") help := flag.Bool("help", false, "справка по использованию") flag.Parse() scanner := bufio.NewScanner(os.Stdin) if *help { catalog.ShowHelp() return } if *list { catalog.ListAll() return } // Поиск через флаг: ./rubric -search ansible if *search != "" { results := catalog.Search(*search) catalog.ShowSearchResults(*search, results) if len(results) > 0 { fmt.Printf(" %s%sВведите номер раздела чтобы открыть (Enter — пропустить):%s ", utils.ColorBold, utils.ColorGreen, utils.ColorReset) if scanner.Scan() { input := strings.TrimSpace(scanner.Text()) if input != "" { n := 0 valid := true for _, ch := range input { if ch >= '0' && ch <= '9' { n = n*10 + int(ch-'0') } else { valid = false break } } if valid && n >= 1 && n <= len(results) { fmt.Println() results[n-1].RunFunc() } } } } return } // -book X -topic Y if *book != "" && *topic != "" { switch *book { case "go", "g", "golang": m, ok := gomodules.Find(*topic) if !ok { fmt.Printf("\n %s%sРаздел '%s' не найден в Go.%s\n", utils.ColorBold, utils.ColorRed, *topic, utils.ColorReset) gomodules.ListModules() os.Exit(1) } m.Run() case "linux", "l", "lnx": m, ok := linuxmodules.Find(*topic) if !ok { fmt.Printf("\n %s%sРаздел '%s' не найден в Linux.%s\n", utils.ColorBold, utils.ColorRed, *topic, utils.ColorReset) linuxmodules.ListModules() os.Exit(1) } m.Run() case "devops", "do", "dev": m, ok := devopsmodules.Find(*topic) if !ok { fmt.Printf("\n %s%sРаздел '%s' не найден в DevOps.%s\n", utils.ColorBold, utils.ColorRed, *topic, utils.ColorReset) devopsmodules.ListModules() os.Exit(1) } m.Run() case "infosec", "sec", "security", "is": m, ok := infosecmodules.Find(*topic) if !ok { fmt.Printf("\n %s%sРаздел '%s' не найден в InfoSec.%s\n", utils.ColorBold, utils.ColorRed, *topic, utils.ColorReset) infosecmodules.ListModules() os.Exit(1) } m.Run() default: fmt.Printf("\n %s%sСправочник '%s' не найден.%s\n", utils.ColorBold, utils.ColorRed, *book, utils.ColorReset) catalog.ListAll() os.Exit(1) } return } // -book X if *book != "" { b, ok := catalog.Find(*book) if !ok { fmt.Printf("\n %s%sСправочник '%s' не найден.%s\n", utils.ColorBold, utils.ColorRed, *book, utils.ColorReset) catalog.ListAll() os.Exit(1) } b.Run(scanner) return } // Интерактивный режим catalog.RunInteractiveWithSearch(scanner) }