terraform-provider-gitea/vendor/github.com/hashicorp/terraform-plugin-docs/schemamd/write_block_type_description.go
dependabot[bot] 4e94047737
Bump github.com/hashicorp/terraform-plugin-docs from 0.14.1 to 0.15.0
Bumps [github.com/hashicorp/terraform-plugin-docs](https://github.com/hashicorp/terraform-plugin-docs) from 0.14.1 to 0.15.0.
- [Release notes](https://github.com/hashicorp/terraform-plugin-docs/releases)
- [Changelog](https://github.com/hashicorp/terraform-plugin-docs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hashicorp/terraform-plugin-docs/compare/v0.14.1...v0.15.0)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/terraform-plugin-docs
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-04 08:39:56 +00:00

100 lines
1.9 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package schemamd
import (
"fmt"
"io"
"strings"
tfjson "github.com/hashicorp/terraform-json"
)
func WriteBlockTypeDescription(w io.Writer, block *tfjson.SchemaBlockType) error {
_, err := io.WriteString(w, "(Block")
if err != nil {
return err
}
switch block.NestingMode {
default:
return fmt.Errorf("unexpected nesting mode for block: %s", block.NestingMode)
case tfjson.SchemaNestingModeSingle:
// nothing
case tfjson.SchemaNestingModeList:
_, err = io.WriteString(w, " List")
if err != nil {
return err
}
case tfjson.SchemaNestingModeSet:
_, err = io.WriteString(w, " Set")
if err != nil {
return err
}
case tfjson.SchemaNestingModeMap:
_, err = io.WriteString(w, " Map")
if err != nil {
return err
}
}
if block.NestingMode == tfjson.SchemaNestingModeSingle {
switch {
case childBlockIsRequired(block):
_, err = io.WriteString(w, ", Required")
if err != nil {
return err
}
case childBlockIsOptional(block):
_, err = io.WriteString(w, ", Optional")
if err != nil {
return err
}
case childBlockIsReadOnly(block):
_, err = io.WriteString(w, ", Read-only")
if err != nil {
return err
}
default:
return fmt.Errorf("block does not match any filter states")
}
} else {
if block.MinItems > 0 {
_, err = io.WriteString(w, fmt.Sprintf(", Min: %d", block.MinItems))
if err != nil {
return err
}
}
}
if block.MaxItems > 0 {
_, err = io.WriteString(w, fmt.Sprintf(", Max: %d", block.MaxItems))
if err != nil {
return err
}
}
if block.Block.Deprecated {
_, err = io.WriteString(w, ", Deprecated")
if err != nil {
return err
}
}
_, err = io.WriteString(w, ")")
if err != nil {
return err
}
desc := strings.TrimSpace(block.Block.Description)
if desc != "" {
_, err = io.WriteString(w, " "+desc)
if err != nil {
return err
}
}
return nil
}