github.com/banzaicloud/operator-tools@v0.28.10/cmd/docs.go (about) 1 // Copyright © 2020 Banzai Cloud 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package main 16 17 import ( 18 "fmt" 19 "path/filepath" 20 21 "emperror.dev/errors" 22 "github.com/MakeNowJust/heredoc" 23 "github.com/banzaicloud/operator-tools/pkg/docgen" 24 "github.com/banzaicloud/operator-tools/pkg/utils" 25 ) 26 27 var logger = utils.Log 28 29 func main() { 30 crds() 31 } 32 33 func crds() { 34 lister := docgen.NewSourceLister( 35 map[string]docgen.SourceDir{ 36 "secret": {Path: "pkg/secret", DestPath: "docs/types"}, 37 "volume": {Path: "pkg/volume", DestPath: "docs/types"}, 38 "base": {Path: "pkg/types", DestPath: "docs/types"}, 39 "overrides": {Path: "pkg/typeoverride", DestPath: "docs/overrides"}, 40 }, 41 logger.WithName("lister")) 42 43 lister.IncludeSources = []string{ 44 ".*types$", 45 ".*override$", 46 } 47 lister.IgnoredSources = []string{ 48 ".*", 49 } 50 51 lister.Index = docgen.NewDoc(docgen.DocItem{ 52 Name: "Readme", 53 DestPath: "docs/types", 54 }, logger.WithName("typedoc")) 55 56 lister.Header = heredoc.Doc(` 57 # Available Types 58 59 For more information please click on the name 60 <center> 61 62 | Name | Description | 63 |---|---|`, 64 ) 65 66 lister.Footer = heredoc.Doc(` 67 </center> 68 `) 69 70 lister.DocGeneratedHook = func(document *docgen.Doc) error { 71 relPath, err := filepath.Rel(lister.Index.Item.DestPath, document.Item.DestPath) 72 if err != nil { 73 return errors.WrapIff(err, "failed to determine relpath for %s", document.Item.DestPath) 74 } 75 lister.Index.Append(fmt.Sprintf("| **[%s](%s)** | %s |", 76 document.DisplayName, 77 filepath.Join(relPath, document.Item.Name+".md"), 78 document.Desc)) 79 return nil 80 } 81 82 if err := lister.Generate(); err != nil { 83 panic(err) 84 } 85 }