rubric/main.go
2026-03-24 16:57:17 +03:00

68 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"bufio"
"flag"
"fmt"
"os"
"rubric/catalog"
"rubric/modules/gomodules"
"rubric/utils"
)
func main() {
book := flag.String("book", "", "открыть справочник напрямую (например: -book go)")
topic := flag.String("topic", "", "открыть раздел (используется вместе с -book)")
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
}
// -book go -topic basics
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()
default:
fmt.Printf("\n %s%sСправочник '%s' не найден.%s\n",
utils.ColorBold, utils.ColorRed, *book, utils.ColorReset)
catalog.ListAll()
os.Exit(1)
}
return
}
// -book go
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.RunInteractive(scanner)
}