mirror of
https://github.com/terraform-docs/terraform-docs.git
synced 2026-03-27 04:48:33 +07:00
add support for .tofu files
Signed-off-by: James Geddes <j@jamesgeddes.pro>
This commit is contained in:
@@ -11,14 +11,14 @@ toc: true
|
||||
Since `v0.12.0`
|
||||
|
||||
Relative path to a file to extract footer for the generated output from. Supported
|
||||
file formats are `.adoc`, `.md`, `.tf`, and `.txt`.
|
||||
file formats are `.adoc`, `.md`, `.tf`, `.tofu`, and `.txt`.
|
||||
|
||||
{{< alert type="info" >}}
|
||||
The whole file content is being extracted as module footer when extracting from
|
||||
`.adoc`, `.md`, or `.txt`.
|
||||
{{< /alert >}}
|
||||
|
||||
To extract footer from `.tf` file you need to use following javascript, c, or java
|
||||
To extract footer from `.tf` or `.tofu` file you need to use following javascript, c, or java
|
||||
like multi-line comment.
|
||||
|
||||
```tf
|
||||
@@ -37,7 +37,7 @@ resource "foo" "bar" { ... }
|
||||
```
|
||||
|
||||
{{< alert type="info" >}}
|
||||
This comment must start at the immediate first line of the `.tf` file
|
||||
This comment must start at the immediate first line of the `.tf` or `.tofu` file
|
||||
before any `resource`, `variable`, `module`, etc.
|
||||
{{< /alert >}}
|
||||
|
||||
|
||||
@@ -11,14 +11,14 @@ toc: true
|
||||
Since `v0.10.0`
|
||||
|
||||
Relative path to a file to extract header for the generated output from. Supported
|
||||
file formats are `.adoc`, `.md`, `.tf`, and `.txt`.
|
||||
file formats are `.adoc`, `.md`, `.tf`, `.tofu`, and `.txt`.
|
||||
|
||||
{{< alert type="info" >}}
|
||||
The whole file content is being extracted as module header when extracting from
|
||||
`.adoc`, `.md`, or `.txt`.
|
||||
{{< /alert >}}
|
||||
|
||||
To extract header from `.tf` file you need to use following javascript, c, or java
|
||||
To extract header from `.tf` or `.tofu` file you need to use following javascript, c, or java
|
||||
like multi-line comment.
|
||||
|
||||
```tf
|
||||
@@ -37,7 +37,7 @@ resource "foo" "bar" { ... }
|
||||
```
|
||||
|
||||
{{< alert type="info" >}}
|
||||
This comment must start at the immediate first line of the `.tf` file
|
||||
This comment must start at the immediate first line of the `.tf` or `.tofu` file
|
||||
before any `resource`, `variable`, `module`, etc.
|
||||
{{< /alert >}}
|
||||
|
||||
|
||||
@@ -108,10 +108,10 @@ func isFileFormatSupported(filename string, section string) (bool, error) {
|
||||
return false, fmt.Errorf("--%s-from value is missing", section)
|
||||
}
|
||||
switch getFileFormat(filename) {
|
||||
case ".adoc", ".md", ".tf", ".txt":
|
||||
case ".adoc", ".md", ".tf", ".tofu", ".txt":
|
||||
return true, nil
|
||||
}
|
||||
return false, fmt.Errorf("only .adoc, .md, .tf, and .txt formats are supported to read %s from", section)
|
||||
return false, fmt.Errorf("only .adoc, .md, .tf, .tofu and .txt formats are supported to read %s from", section)
|
||||
}
|
||||
|
||||
func loadHeader(config *print.Config) (string, error) {
|
||||
@@ -146,7 +146,8 @@ func loadSection(config *print.Config, file string, section string) (string, err
|
||||
}
|
||||
return "", err // user explicitly asked for a file which doesn't exist
|
||||
}
|
||||
if getFileFormat(file) != ".tf" {
|
||||
format := getFileFormat(file)
|
||||
if format != ".tf" && format != ".tofu" {
|
||||
content, err := os.ReadFile(filepath.Clean(filename))
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -161,6 +161,14 @@ func TestIsFileFormatSupported(t *testing.T) {
|
||||
errText: "",
|
||||
section: "header",
|
||||
},
|
||||
{
|
||||
name: "is file format supported",
|
||||
filename: "main.tofu",
|
||||
expected: true,
|
||||
wantErr: false,
|
||||
errText: "",
|
||||
section: "header",
|
||||
},
|
||||
{
|
||||
name: "is file format supported",
|
||||
filename: "main.txt",
|
||||
@@ -174,7 +182,7 @@ func TestIsFileFormatSupported(t *testing.T) {
|
||||
filename: "main.doc",
|
||||
expected: false,
|
||||
wantErr: true,
|
||||
errText: "only .adoc, .md, .tf, and .txt formats are supported to read header from",
|
||||
errText: "only .adoc, .md, .tf, .tofu and .txt formats are supported to read header from",
|
||||
section: "header",
|
||||
},
|
||||
{
|
||||
@@ -189,7 +197,7 @@ func TestIsFileFormatSupported(t *testing.T) {
|
||||
filename: "main.doc",
|
||||
expected: false,
|
||||
wantErr: true,
|
||||
errText: "only .adoc, .md, .tf, and .txt formats are supported to read footer from",
|
||||
errText: "only .adoc, .md, .tf, .tofu and .txt formats are supported to read footer from",
|
||||
section: "footer",
|
||||
},
|
||||
{
|
||||
@@ -405,7 +413,7 @@ func TestLoadSections(t *testing.T) {
|
||||
file: "wrong-formate.docx",
|
||||
expected: "",
|
||||
wantErr: true,
|
||||
errText: "only .adoc, .md, .tf, and .txt formats are supported to read footer from",
|
||||
errText: "only .adoc, .md, .tf, .tofu and .txt formats are supported to read footer from",
|
||||
section: "footer",
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user