Move print package from internal to public

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
This commit is contained in:
Khosrow Moossavi
2021-09-28 14:45:36 -04:00
parent 90942f73b8
commit d2fe2b1b29
78 changed files with 1143 additions and 950 deletions

View File

@@ -276,6 +276,48 @@ content: |-
```
````
## Build on top of terraform-docs
terraform-docs primary use-case is to be utilized as a standalone binary, but
some parts of it is also available publicly and can be imported in your project
as a library.
```go
import (
"github.com/terraform-docs/terraform-docs/format"
"github.com/terraform-docs/terraform-docs/print"
"github.com/terraform-docs/terraform-docs/terraform"
)
// buildTerraformDocs for module root `path` and provided content `tmpl`.
func buildTerraformDocs(path string, tmpl string) (string, error) {
config := print.DefaultConfig()
config.ModuleRoot = path // module root path (can be relative or absolute)
_, options := config.Extract()
module, err := terraform.LoadWithOptions(options)
if err != nil {
return "", err
}
// Generate in Markdown Table format
formatter := format.NewMarkdownTable(config)
if err := formatter.Generate(module); err != nil {
return "", err
}
// // Note: if you don't intend to provide additional template for the generated
// // content, or the target format doesn't provide templating (e.g. json, yaml,
// // xml, or toml) you can use `Content()` function instead of `ExecuteTemplate()`.
// // `Content()` returns all the sections combined with predefined order.
// return formatter.Content(), nil
return formatter.ExecuteTemplate(tmpl)
}
```
## Documentation
- **Users**