rubric/main.go
2026-04-06 11:02:36 +03:00

78 lines
1.9 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/modules/linuxmodules"
"rubric/utils"
)
func main() {
book := flag.String("book", "", "открыть справочник напрямую (go, linux)")
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 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()
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.RunInteractive(scanner)
}