Commit Graph

68 Commits

Author SHA1 Message Date
Yutaro Suzuki
38a327a66c Add fish shell completion
Signed-off-by: Yutaro Suzuki <yutaro.suzuki@cloudys.dev>
2023-06-30 02:32:29 +09:00
Khosrow Moossavi
54dc0f5a7c Add recursive config to .terraform-docs.yml file
Up to now there was only one way to enable recursive execution and that
was with `--recursive` CLI flag. This enables the same behavior but
within config file (i.e. `.terraform-docs.yml`)

Example:

```yaml
recursive:
  enabled: false
  path: modules
```

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-30 15:53:22 -04:00
Khosrow Moossavi
d2fe2b1b29 Move print package from internal to public
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-09-28 15:04:07 -04:00
Poojitha Bikki
045707beee feat: Add new flag 'read-comments' to optionally process comments as description
fixes issue #552

- process description from comments

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- fix module tests

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- optionally read comments for output vars description

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- set default to true

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- run make docs

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- change option name

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- add option in doc generator; make docs

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- add config 'ReadComments'

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- Fix alphabetic order for 'ReadComments' setting

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- add read-comments in docs

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- add test for readcomments option

Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>

- update 'read-comments' flag description

Co-authored-by: Khosrow Moossavi <khos2ow@gmail.com>
Signed-off-by: Poojitha Bikki <50849668+poojitha-bikki@users.noreply.github.com>
2021-09-24 18:04:39 -05:00
Nassos Kat
f61375077e Add 'HideEmpy' section bool flag
* Add 'HideEmpy' section to Settings

Signed-off-by: akatsadimas <nkatsadim@gmail.com>

* Address review comments

fixed linting and docs, moved HideEmpty to Settings struct

Signed-off-by: akatsadimas <nkatsadim@gmail.com>

* Address review comment

document hideempty configuration option

Signed-off-by: akatsadimas <nkatsadim@gmail.com>

* Address review comments - improve docs

Signed-off-by: akatsadimas <nkatsadim@gmail.com>
2021-08-31 17:17:16 -04:00
Khosrow Moossavi
1450ee9a10 Generate submodules documents with '--resurcive' flag
Considering the file strucutre below of main module and its submodules,
now it is possible to generate documentation for them main and all its
submodules in one execution, with `--recursive` flag.

Note that generating documentation recursively is allowed only with
`--output-file` set.

Path to find submodules can be configured with `--recursive-path`
(defaults to `modules`).

Each submodule can also have their own `.terraform-docs.yml` confi file,
to override configuration from root module.

```
.
├── README.md
├── main.tf
├── modules
│   └── my-sub-module
│       ├── README.md
│       ├── main.tf
│       ├── variables.tf
│       └── versions.tf
├── outputs.tf
├── variables.tf
└── versions.tf
```

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-08-10 18:22:40 -04:00
Khosrow Moossavi
5256426650 Ignore extracting versions from terraform.lock.hcl
New flag, `--lockfile`, is added to control whether ignore reading
.terraform.lock.hcl file in an attempt to extract the exact version of
provider being used or not. Default is true.

If set to true, exact version of provider available in lock file at the
time of execution will be extracted. If set to false, the version in .tf
file will be used (either exact, or a constrained version: >=, ~>, ...)

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-07-22 19:48:39 -04:00
Ricardo Herrera
21eaab4fc7 add output-check option for outputs
adding option to compare outputted file with generated
terraform-doc and fail if different

Signed-off-by: Ricardo Herrera <rickhl@outlook.com>
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-07-22 17:21:11 -04:00
Khosrow Moossavi
d77324cc02 Add new '--show all' and '--hide all' sections
New psuedo section `all` is added and can be used to show or hide _all_
sections. This can be used as a replacement for, now, deprecated and
removed `--show-all` and `--hide-all` flags.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-06-02 13:01:25 -04:00
Khosrow Moossavi
25f03b4cf4 Remove deprecated '--show-all' and '--hide-all' flags
In v0.13.0 flags `--show-all` and `--hide-all` have been deprecated. And
they are completely being removed now (two releases after original
announcement)

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-06-02 13:01:13 -04:00
Khosrow Moossavi
258f4603fb Remove deprecated '--sort-by-XXX' flags
In v0.13.0 flags `--sort-by-required` and `--sort-by-type` have been
deprecated in favor of `--sort-by required` and `--sort-by type`
respectively. And they are completely being removed now (two releases
after original announcement)

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-06-02 13:00:38 -04:00
Khosrow Moossavi
6820b4c2ce Normalize version to prevent malformed error
As part of this normalization the following is made sure:

- leading `v` is shown in `-v, --version` and `version` command
- commit hash is shown in `-v, --version` and `version` command
- build date is removed
- version core (without pre-release) is used for constraint comparison

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-05-26 13:22:30 -04:00
Khosrow Moossavi
2f088f2544 Add '--html bool' flag and config to Markdown
This is to control the generated HTML tags inside markdown output. If
set to false no html tags (e.g. `<br>`, `<pre>`) will be generated. And
as a workaround the multi-line codeblock will be converted to single
line with linebreak converted to `<SPACE>`.

For example:

```
{
  "bar": {
    "bar": "bar",
    "foo": "bar"
  },
  "buzz": [
    "fizz",
    "buzz"
  ],
  "fizz": []
}
```

will be converted to:

```
{ "bar": { "bar": "bar", "foo": "bar" }, "buzz": [ "fizz", "buzz" ], "fizz": [] }
```

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-05-25 13:23:28 -04:00
Khosrow Moossavi
845469c45f Support outputing to file for absolute path
`--output-file` or corresponding `output.file` config can now support
absolute path as well as relative path to root of module foler. For
example all of the followings are valid:

    $ cd /path/to/module
    $ tree .
    .
    ├── docs
    │   └── README.md
    ├── ...
    └── main.tf

    # this works, relative path
    $ terraform-docs markdown table --output-file ../docs/README.md .

    # so does this, absolute path
    $ terraform-docs markdown table --output-file /path/to/module/docs/README.md .

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-27 13:06:55 -04:00
Khosrow Moossavi
8c531b6544 Deprecate --show-all and --hide-all flags
As of `v0.13.0` flags `--show-all` and `--hide-all` are deprecated in
favor of explicit use of `--show` and `--hide`. In other words when
`--show <section>` is used, only `<section>` will be shown. If you want
to show multiple sections and hide the rest you can specify multiple
`--show` flags. The same logic is also applied to `--hide`.

    # show 'inputs' and hide everything else
    $ terraform-docs --show inputs <formatter>

    # show 'inputs' and show 'outputs' and hide everything else
    $ terraform-docs --show inputs --show outputs <formatter>

    # hide 'header' and show everything else
    $ terraform-docs --hide header <formatter>

    # hide 'header' and hide 'providers' and show everything else
    $ terraform-docs --hide header --hide providers <formatter>

Note: Using `--show` or `--hide` CLI flag will completely override the
values from `.terraform-docs.yml`. Example:

    $ cat .terraform-docs.yml
    sections:
      show:
        - inputs
        - outputs

    # example 1: this will only show 'providers'
    $ terraform-docs --show providers .

    # example 2: this will hide 'inputs' and hide 'providers' and show everything else
    $ terraform-docs --hide inputs --hide providers .

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-20 11:50:58 -04:00
Khosrow Moossavi
930bfbaf30 Merge pull request #466 from mikiya771/feature/tfvars-hcl/add-description-flag
Feature/lssue461/add description flag
2021-04-14 12:57:44 -04:00
mikiya771
d914ca71e6 Add a flag for showing description with hcl formatted tfvars
Signed-off-by: mikiya771 <22876341+mikiya771@users.noreply.github.com>

add: cli flag of show description

Signed-off-by: mikiya771 <22876341+mikiya771@users.noreply.github.com>

add: test for tfvars-hcl description flag

Signed-off-by: mikiya771 <22876341+mikiya771@users.noreply.github.com>

docs: add tfvars-hcl flag

Signed-off-by: mikiya771 <22876341+mikiya771@users.noreply.github.com>

fix: inser new lines around value with description

Signed-off-by: mikiya771 <22876341+mikiya771@users.noreply.github.com>

fix: replace with -1 to replaceall for linter

Signed-off-by: mikiya771 <22876341+mikiya771@users.noreply.github.com>

fix: use simple format for linter

Signed-off-by: mikiya771 <22876341+mikiya771@users.noreply.github.com>

fix: padding format as terraform-fmt-way

Signed-off-by: mikiya771 <22876341+mikiya771@users.noreply.github.com>
2021-04-14 21:21:37 +09:00
Khosrow Moossavi
557d53dd1e Deprecate '--sort-by-XX' in favor of '--sort-by XX'
This deprecates sort by flags in favor of their corresponding dynamic
valued ones. Affected flags are:

- `--sort-by-required`
- `--sort-by-type`

In return new `--sort-by string` is added with following values:

- `name` (default)
- `required`
- `type`

Note that the behavior of `--sort bool` was not changed and to disable
sorting altogether you can run `--sort false`.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-04-12 18:34:42 -04:00
Anthony O'Brien
e4a3a84e0e print cli errors to stderr
This is a small change that prints any errors that surface when
executing the cli (i.e., `cmd.Execute()`) to stderr rather than
stdout.

When redirecting streams, its useful to keep errors separated from
program output so that in the case of an error the message won't be
redirected and is still surfaced. This issue came up for me when
using this terraform-docs in a script, where I encountered an error:

    $ terraform-docs markdown path/not/to/mod > outfile
    zsh: exit 1     terraform-docs markdown path/not/to/mod > outfile

When I ran the above command in my script an error was generated
because the path was incorrect, however the error message wasn't
printed to my console and the outfile was filled with the error
message. The change here modifies the cli's output to instead show:

    $ terraform-docs markdown path/not/to/mod > outfile
    Error: Failed to read module directory: Module directory path/not/to/mod does not exist or cannot be read.
    zsh: exit 1     terraform-docs markdown path/not/to/mod > outfile

and the outfile is empty.

Signed-off-by: Anthony O'Brien <anthony@bearonis.com>
2021-03-26 20:07:35 -04:00
Simon Clifford
aa1e6bbf59 Add support for footer docs
Enables a footer to be appended to the end of a generated document
sourced from tf files or documents in the same way as the header

Adds the `footer-from` field to the config yml
Adds the `--footer-from` flag to the cli

Signed-off-by: Simon Clifford <siclifford@gmail.com>
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-03-15 14:51:00 -04:00
Khosrow Moossavi
a3bafd6018 Save generated content directly into a file
There are two modes for saving into file:

- inject: partially replace the target file with generated output
- replace: completely replace the target file with generated output

The output generated by formatters (markdown, asciidoc, etc) will be
inserted into a template before getting saved into the file. This
template can be customized with '--output-template' CLI flag or
corresponding item in '.terraform-docs.yml' config file. Its default
value is:

```
<!-- BEGIN_TF_DOCS -->
{{ .Content }}
<!-- END_TF_DOCS -->
```

This consists of three items, all of them are mandatory:

- begin comment
- content variable
- end comment

You may change the wording of comment as you wish, but the comment must
be present in the template.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-03-09 16:40:22 -05:00
Khosrow Moossavi
3d39a94e39 Add option to hide Type and Default columns
Two new flags are added: '--default bool' and '--type bool' to
control the visibility of Default and Type columns and section
respectively in Markdown and AsciiDoc.

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-03-02 14:17:03 -05:00
nitrocode
02f490dc65 --anchor to add anchors for markdown, asciidocs
Signed-off-by: nitrocode <nitrocode@users.noreply.github.com>
2021-03-02 12:47:44 -05:00
Khosrow Moossavi
25d2ff4e53 Completely remove deprecated '--no-XXX' flags
In v0.10.0 flags '--no-XXX' have been deprecated in favor of their
counterparts in the format of '--X=false' (e.g. --no-header and
--header=false). And they are completely being removed now (two releases
after original announcement)

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-02-23 18:46:02 -05:00
Heiko Neblung
2575a40e78 added output section for modulecalls
Signed-off-by: Heiko Neblung <Heiko.Neblung@t-systems.com>
2021-02-10 05:40:50 +01:00
Khosrow Moossavi
54fc067bf4 Add support for plugin execution
Plugin can be developed on top of terraform-docs/plugin-sdk and made
available to terraform-docs core project in:

- ~/.tfdocs.d/plugins/ or
- ./.tfdocs.d/plugins/ (this takes precedence if exists)

Refer to the following for more details and examples:

- https://github.com/terraform-docs/plugin-sdk
- https://github.com/terraform-docs/tfdocs-format-template

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-02-02 18:27:04 -05:00
Tim Earle
533a82b900 Add section for Resources
Signed-off-by: Tim Earle <earle.timothy@gmail.com>
2021-01-31 09:59:33 -05:00
Khosrow Moossavi
44b3361b22 Add license header to codebase files
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-01-28 12:29:11 -05:00
Khosrow Moossavi
fd97ec5930 feat: Add support for .terraform-docs.yml config file (#272)
* Add support for .terraform-docs.yml config file

* add config reader

* add usage documentation and reference guide

* typo

* update docs
2020-07-13 22:06:30 -04:00
Khosrow Moossavi
dfeaaecdc4 Migrate to github.com/terraform-docs org (#288)
* Migrate to github.com/terraform-docs org

* remove codecov token

* update maintenance notice in README
2020-07-06 19:43:25 -04:00
Khosrow Moossavi
e0404399a7 feat: Add new flags: --show, --show-all, --hide-all (#267)
* Add new flags: --show, --show-all, --hide-all

* add deprecated flags to Config

* update docs

* add implementation for new flags

Examples:

- hide all sections except one (or more): `terraform-docs --hide-all --show <name> ...`
- show all sections except one (or more): `terraform-docs --show-all --hide <name> ...`
2020-05-25 12:08:52 -04:00
Khosrow Moossavi
04a9ef49eb refactor: Refactor cli implemention and configuration (#266)
* Refactor cli implemention and configuration

* cleanup
2020-05-20 22:21:19 -04:00
Khosrow Moossavi
23c50e0ad8 refactor: Deprecate multiple flags in favor of new ones (#265)
BREAKING CHANGE: - Following flags have been deprecated and will be
removed in the following releases:

  - Flag `--no-color` has been deprecated, use `--color=false` instead

  - Flag `--no-escape` has been deprecated, use `--escape=false` instead

  - Flag `--no-header` has been deprecated, use `--hide header` instead

  - Flag `--no-inputs` has been deprecated, use `--hide inputs` instead

  - Flag `--no-outputs` has been deprecated, use `--hide outputs` instead

  - Flag `--no-providers` has been deprecated, use `--hide providers` instead

  - Flag `--no-requirements` has been deprecated, use `--hide requirements` instead

  - Flag `--no-required` has been deprecated, use `--required=false` instead

  - Flag `--no-sensitive` has been deprecated, use `--sensitive=false` instead

  - Flag `--no-sort` has been deprecated, use `--sort=false` instead
2020-05-20 11:49:25 -04:00
Khosrow Moossavi
8de80061fe Put terraform-docs imports after 3rd-party packages (#264) 2020-05-19 18:18:15 -04:00
Khosrow Moossavi
b397b7d46b feat: Add support for TOML renderer (#197)
* Add support for TOML renderer

* Add kind:formatter to toml command

* update docs

* adjust tests after merge

* fix after merge

* adjust tests after merge

* update docs

* remove vendor leftovers

* update doc

* update tests
2020-05-14 12:41:21 -04:00
Khosrow Moossavi
b25909b537 feat: Add new flag to sort inputs by type (#246)
* Add new flag to sort inputs by type

* add more tests

* revert renames
2020-04-13 17:43:21 -04:00
Khosrow Moossavi
b6a6ad1bbf refactor: Remove deprecated flags (#229)
BREAKING CHANGE: - Flags `--with-aggregate-type-defaults` and
`--sort-inputs-by-required` were marked as deprecated in v0.8.2
and now are removed.
2020-04-13 12:54:48 -04:00
Rubén del Campo
37375db283 feat: Add support for AsciiDoc renderer (#241)
* Implement AsciiDoc renderer

* Add missing tests to maintain expected code coverage

* Keep alphabetical order

* Refactor indent function (accept char argument and make homogeneous for both MD and Adoc renderers)

* Force asciidoc syntax in every table column

* Remove extra NL before code blocks and add autowidth tables

* Move char argument after settings in indent function

* Implement new factory function for asciidoc renderer

* Update asciidoc table docs

* Return empty indentation if no indent scpecified

* Prevent adding a trailing whitespace in table rows

* Change asciidoc alias to match file extension

* Update docs
2020-04-12 15:22:53 -04:00
Khosrow Moossavi
c196c7cc49 refactor: Add factory function to return format types (#243) 2020-04-10 19:08:37 -04:00
Khosrow Moossavi
80172d77f4 fix: Don't crash when reading header if 'main.tf' not found (#235)
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2020-04-02 16:17:30 -04:00
Khosrow Moossavi
40bd96be44 docs: Enhance automatic document generation (#227)
* Enhance automatic document generation

* update contribuor guide

* fix broken link
2020-03-29 18:17:55 -04:00
Khosrow Moossavi
9043f268ad feat: Add support for tfvars hcl and json commands (#226)
* Add support for tfvars hcl and json commands

* fix docs generation header issue

* align padding of hcl tfvars items

* add more tests

* update docs

* wording
2020-03-27 15:02:09 -04:00
Julien Duchesne
4365b4997b fix: --no-header should not attempt reading main.tf file (#224)
* --no-header should stop terraform-docs from reading the main.tf file

Our projects do not have that file. Even with `--no-header`, terraform-docs crashes

* Add tests for empty configs in every format
+ Add a ShowHeader attribute in Options
+ Check for that option in loadHeader
2020-03-25 15:25:16 -04:00
Julien Duchesne
2caf4af15d feat: Allow hiding the "Sensitive" column in markdown (#223)
* Allow hiding the "Sensitive" column in markdown

Use case: for projects where all outputs are expected to not be sensitive, it adds noise

* Document the new --no-sensitive option

* Fixed tests, they were written on a previous branch

* Fix tests following merge with master

* Update internal/format/document.go

Co-Authored-By: Khosrow Moossavi <khos2ow@gmail.com>

Co-authored-by: Khosrow Moossavi <khos2ow@gmail.com>
2020-03-25 11:56:23 -04:00
Khosrow Moossavi
b6241751d9 feat: Add section for module requirements (#222)
* Add section for module requirements

* cleanup

* reorder items logically
2020-03-24 14:20:13 -04:00
Khosrow Moossavi
01c8fa1c61 feat: Add support for fetching the module header from any file (#217)
* Add support for fetching the module header from any file

* fix the failing test because of lines reader
2020-03-12 13:58:35 -04:00
Khosrow Moossavi
79e926ee43 enhance: Add extensive tests coverage for all the packages (#208)
* Add more test coverage

* add format/util test

* add tfconf/input test

* add line reader test

* cleanup

* add tfconf/output test

* improve internal/module/input coverage

* improve internal/module/options coverage

* improve internal/reader coverage

* improve internal/types coverage

* appease lint

* improve pkg/tfconf/output coverage

* add coverage to test target in makefile

* improve pkg/tmpl/sanitizer coverage

* use 'test' target on action

* always prepare codecov report, even if tests are failing

* fix double-space new line issue

* extensive tests for escaping characters

* enhance nad fix escape characters failing tests

* improve internal/module/module coverage

* improve pkg/tmpl/template coverage

* cleanup
2020-03-09 20:56:29 -04:00
Khosrow Moossavi
b716a25811 feat: Add support for XML renderer (#198)
* Add support for XML renderer

* formatting

* update docs
2020-02-26 14:44:50 -05:00
Khosrow Moossavi
4ff4582dff feat: Show sensitivity of the output value in rendered result (#207) 2020-02-26 12:08:24 -05:00
Khosrow Moossavi
38e18970ed refactor: Introduce Format interface and expose to public pkg (#195)
* Introduce format interface and expose to public pkg

* fix issues after merge

* don't panic

* Rename TFString back to String
2020-02-19 14:07:10 -05:00