// ops-generator — генератор per-service operations документации. package main import ( "fmt" "io/fs" "os" "path/filepath" "sort" "strings" "gopkg.in/yaml.v3" "ops-generator/internal/docs" "ops-generator/internal/types" ) func main() { repoRoot, err := findRepoRoot() if err != nil { panic(err) } yamlDir := strings.TrimSpace(os.Getenv("NUBES_OPS_YAML_DIR")) if yamlDir == "" { yamlDir = filepath.Join(repoRoot, "resources_ops_yaml") } docsDir := strings.TrimSpace(os.Getenv("NUBES_OPS_DOCS_DIR")) if docsDir == "" { root := filepath.Dir(repoRoot) docsDir = filepath.Join(root, "docs", "30_registry", "resources", "operations") } if err := os.MkdirAll(docsDir, 0o755); err != nil { panic(err) } entries := []docs.Entry{} err = filepath.WalkDir(yamlDir, func(path string, d fs.DirEntry, err error) error { if err != nil { return err } if d.IsDir() || !strings.HasSuffix(d.Name(), ".yaml") { return nil } b, err := os.ReadFile(path) if err != nil { return err } var spec types.ServiceOpsSpec if err := yaml.Unmarshal(b, &spec); err != nil { return err } if spec.ServiceID == 0 || spec.Name == "" { return nil } fileName := fmt.Sprintf("%d_%s.md", spec.ServiceID, docs.Name(spec.Name)) outPath := filepath.Join(docsDir, fileName) if err := docs.ServiceDoc(outPath, spec); err != nil { return err } entries = append(entries, docs.Entry{ ServiceID: spec.ServiceID, Name: spec.Name, File: fileName, Title: docs.Title(spec), OpCount: len(spec.Operations), }) return nil }) if err != nil { panic(err) } sort.Slice(entries, func(i, j int) bool { return entries[i].ServiceID < entries[j].ServiceID }) if err := docs.Index(filepath.Join(docsDir, "index.md"), entries); err != nil { panic(err) } fmt.Printf("Generated %d operations docs in %s\n", len(entries), docsDir) } func findRepoRoot() (string, error) { wd, err := os.Getwd() if err != nil { return "", err } current := wd for i := 0; i < 8; i++ { candidate := filepath.Join(current, "resources_yaml") info, err := os.Stat(candidate) if err == nil && info.IsDir() { return current, nil } parent := filepath.Dir(current) if parent == current { break } current = parent } return "", fmt.Errorf("failed to locate provider repo root") }