Skip to content

Commit 90942f7

Browse files
committed
Move format package from internal to public
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
1 parent ca8f833 commit 90942f7

File tree

248 files changed

+62
-17
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

248 files changed

+62
-17
lines changed

internal/format/asciidoc_document.go renamed to format/asciidoc_document.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewAsciidocDocument(settings *print.Settings) print.Engine {
3737
tt := template.New(settings, items...)
3838
tt.CustomFunc(gotemplate.FuncMap{
3939
"type": func(t string) string {
40-
result, extraline := printFencedAsciidocCodeBlock(t, "hcl")
40+
result, extraline := PrintFencedAsciidocCodeBlock(t, "hcl")
4141
if !extraline {
4242
result += "\n"
4343
}
@@ -47,7 +47,7 @@ func NewAsciidocDocument(settings *print.Settings) print.Engine {
4747
if v == "n/a" {
4848
return v
4949
}
50-
result, extraline := printFencedAsciidocCodeBlock(v, "json")
50+
result, extraline := PrintFencedAsciidocCodeBlock(v, "json")
5151
if !extraline {
5252
result += "\n"
5353
}

internal/format/asciidoc_table.go renamed to format/asciidoc_table.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ func NewAsciidocTable(settings *print.Settings) print.Engine {
3737
tt := template.New(settings, items...)
3838
tt.CustomFunc(gotemplate.FuncMap{
3939
"type": func(t string) string {
40-
inputType, _ := printFencedCodeBlock(t, "")
40+
inputType, _ := PrintFencedCodeBlock(t, "")
4141
return inputType
4242
},
4343
"value": func(v string) string {
4444
var result = "n/a"
4545
if v != "" {
46-
result, _ = printFencedCodeBlock(v, "")
46+
result, _ = PrintFencedCodeBlock(v, "")
4747
}
4848
return result
4949
},
File renamed without changes.

format/doc.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Copyright 2021 The terraform-docs Authors.
3+
4+
Licensed under the MIT license (the "License"); you may not
5+
use this file except in compliance with the License.
6+
7+
You may obtain a copy of the License at the LICENSE file in
8+
the root directory of this source tree.
9+
*/
10+
11+
// Package format provides different, out of the box supported, output formats.
12+
//
13+
// Usage
14+
//
15+
// A specific format can be instantiated either for `format.Factory()` function or
16+
// directly calling its function (e.g. `NewMarkdownTable`, etc)
17+
//
18+
// formatter, err := format.Factory("markdown table", settings)
19+
// if err != nil {
20+
// return err
21+
// }
22+
//
23+
// generator, err := formatter.Generate(tfmodule)
24+
// if err != nil {
25+
// return err
26+
// }
27+
//
28+
// output, err := generator.ExecuteTemplate("")
29+
// if err != nil {
30+
// return err
31+
// }
32+
//
33+
// Supported formats are:
34+
//
35+
// • `NewAsciidocDocument`
36+
// • `NewAsciidocTable`
37+
// • `NewJSON`
38+
// • `NewMarkdownDocument`
39+
// • `NewMarkdownTable`
40+
// • `NewPretty`
41+
// • `NewTfvarsHCL`
42+
// • `NewTfvarsJSON`
43+
// • `NewTOML`
44+
// • `NewXML`
45+
// • `NewYAML`
46+
//
47+
package format
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

internal/format/markdown_document.go renamed to format/markdown_document.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewMarkdownDocument(settings *print.Settings) print.Engine {
3535
tt := template.New(settings, items...)
3636
tt.CustomFunc(gotemplate.FuncMap{
3737
"type": func(t string) string {
38-
result, extraline := printFencedCodeBlock(t, "hcl")
38+
result, extraline := PrintFencedCodeBlock(t, "hcl")
3939
if !extraline {
4040
result += "\n"
4141
}
@@ -45,7 +45,7 @@ func NewMarkdownDocument(settings *print.Settings) print.Engine {
4545
if v == "n/a" {
4646
return v
4747
}
48-
result, extraline := printFencedCodeBlock(v, "json")
48+
result, extraline := PrintFencedCodeBlock(v, "json")
4949
if !extraline {
5050
result += "\n"
5151
}

internal/format/markdown_table.go renamed to format/markdown_table.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ func NewMarkdownTable(settings *print.Settings) print.Engine {
3535
tt := template.New(settings, items...)
3636
tt.CustomFunc(gotemplate.FuncMap{
3737
"type": func(t string) string {
38-
inputType, _ := printFencedCodeBlock(t, "")
38+
inputType, _ := PrintFencedCodeBlock(t, "")
3939
return inputType
4040
},
4141
"value": func(v string) string {
4242
var result = "n/a"
4343
if v != "" {
44-
result, _ = printFencedCodeBlock(v, "")
44+
result, _ = PrintFencedCodeBlock(v, "")
4545
}
4646
return result
4747
},
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

internal/format/tfvars_json_test.go renamed to format/tfvars_json_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/*
22
Copyright 2021 The terraform-docs Authors.
3-
43
Licensed under the MIT license (the "License"); you may not
54
use this file except in compliance with the License.
6-
75
You may obtain a copy of the License at the LICENSE file in
86
the root directory of this source tree.
97
*/
File renamed without changes.
File renamed without changes.

internal/format/util.go renamed to format/util.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,24 @@ func sanitize(markdown string) string {
4444
return result
4545
}
4646

47-
// printFencedCodeBlock prints codes in fences, it automatically detects if
47+
// PrintFencedCodeBlock prints codes in fences, it automatically detects if
4848
// the input 'code' contains '\n' it will use multi line fence, otherwise it
4949
// wraps the 'code' inside single-tick block.
5050
// If the fenced is multi-line it also appens an extra '\n` at the end and
5151
// returns true accordingly, otherwise returns false for non-carriage return.
52-
func printFencedCodeBlock(code string, language string) (string, bool) {
52+
func PrintFencedCodeBlock(code string, language string) (string, bool) {
5353
if strings.Contains(code, "\n") {
5454
return fmt.Sprintf("\n\n```%s\n%s\n```\n", language, code), true
5555
}
5656
return fmt.Sprintf("`%s`", code), false
5757
}
5858

59-
// printFencedAsciidocCodeBlock prints codes in fences, it automatically detects if
59+
// PrintFencedAsciidocCodeBlock prints codes in fences, it automatically detects if
6060
// the input 'code' contains '\n' it will use multi line fence, otherwise it
6161
// wraps the 'code' inside single-tick block.
6262
// If the fenced is multi-line it also appens an extra '\n` at the end and
6363
// returns true accordingly, otherwise returns false for non-carriage return.
64-
func printFencedAsciidocCodeBlock(code string, language string) (string, bool) {
64+
func PrintFencedAsciidocCodeBlock(code string, language string) (string, bool) {
6565
if strings.Contains(code, "\n") {
6666
return fmt.Sprintf("\n[source,%s]\n----\n%s\n----\n", language, code), true
6767
}

internal/format/util_test.go renamed to format/util_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func TestFenceCodeBlock(t *testing.T) {
122122
for _, tt := range tests {
123123
t.Run(tt.name, func(t *testing.T) {
124124
assert := assert.New(t)
125-
actual, extraline := printFencedCodeBlock(tt.code, tt.language)
125+
actual, extraline := PrintFencedCodeBlock(tt.code, tt.language)
126126

127127
assert.Equal(tt.expected, actual)
128128
assert.Equal(tt.extraline, extraline)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

internal/cli/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/spf13/viper"
2424

2525
pluginsdk "github.com/terraform-docs/plugin-sdk/plugin"
26-
"github.com/terraform-docs/terraform-docs/internal/format"
26+
"github.com/terraform-docs/terraform-docs/format"
2727
"github.com/terraform-docs/terraform-docs/internal/plugin"
2828
"github.com/terraform-docs/terraform-docs/internal/version"
2929
"github.com/terraform-docs/terraform-docs/terraform"

scripts/docs/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/spf13/cobra"
2424

2525
"github.com/terraform-docs/terraform-docs/cmd"
26-
"github.com/terraform-docs/terraform-docs/internal/format"
26+
"github.com/terraform-docs/terraform-docs/format"
2727
"github.com/terraform-docs/terraform-docs/internal/print"
2828
"github.com/terraform-docs/terraform-docs/terraform"
2929
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy