refactor: merge ops-generator into docs-generator as --ops mode
Single binary, single go.mod — no divergence risk. Run: docs-generator --ops (or regular docs-generator for resource docs)
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"docs-generator/internal/ops"
|
||||
"docs-generator/internal/types"
|
||||
"docs-generator/internal/writers"
|
||||
)
|
||||
@@ -25,9 +26,16 @@ func main() {
|
||||
excludeFlag := flag.String("exclude", "", "Comma-separated resource names to skip")
|
||||
versionFlag := flag.String("version", "", "Provider version for example block")
|
||||
apiEndpointFlag := flag.String("api-endpoint", "https://deck-api.ngcloud.ru/api/v1/index.cfm", "API endpoint for example block")
|
||||
opsFlag := flag.Bool("ops", false, "Generate per-service operations docs (resources_ops_yaml → docs/.../operations)")
|
||||
flag.Parse()
|
||||
|
||||
root := detectRoot()
|
||||
|
||||
// --ops mode: generate per-service operations documentation
|
||||
if *opsFlag {
|
||||
runOpsMode(root)
|
||||
return
|
||||
}
|
||||
resourcesDir := pickPath(*resourcesDirFlag, filepath.Join(root, "provider", "resources_yaml"))
|
||||
docsDir := pickPath(*docsDirFlag, filepath.Join(root, "docs", "30_registry", "resources"))
|
||||
servicesList := pickPath(*servicesListFlag, filepath.Join(root, "devops", "config", "services_list.txt"))
|
||||
@@ -171,3 +179,60 @@ func loadSpecs(dir string, ordered []types.ServiceMeta) []types.ServiceSpec {
|
||||
}
|
||||
return specs
|
||||
}
|
||||
|
||||
// runOpsMode генерирует per-service operations документацию.
|
||||
func runOpsMode(root string) {
|
||||
yamlDir := pickPath(os.Getenv("NUBES_OPS_YAML_DIR"), filepath.Join(root, "provider", "resources_ops_yaml"))
|
||||
docsDir := pickPath(os.Getenv("NUBES_OPS_DOCS_DIR"), filepath.Join(root, "docs", "30_registry", "resources", "operations"))
|
||||
|
||||
if err := os.MkdirAll(docsDir, 0o755); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
entries := []ops.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 ops.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, ops.Name(spec.Name))
|
||||
outPath := filepath.Join(docsDir, fileName)
|
||||
if err := ops.ServiceDoc(outPath, spec); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
entries = append(entries, ops.Entry{
|
||||
ServiceID: spec.ServiceID,
|
||||
Name: spec.Name,
|
||||
File: fileName,
|
||||
Title: ops.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 := ops.Index(filepath.Join(docsDir, "index.md"), entries); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Printf("Generated %d operations docs in %s\n", len(entries), docsDir)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user