Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/generate defaults #81

Merged
merged 29 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
914689b
refactor: rename write to write_doc
moritzrp Oct 4, 2024
c7e9191
feat: add method to generate defaults dict
moritzrp Oct 4, 2024
2460a1c
feat: add method to write defaults dict to a file
moritzrp Oct 4, 2024
59ab56c
feat: add defaults command
moritzrp Oct 4, 2024
36e9607
enhancement: specify output style parameters
moritzrp Oct 5, 2024
3747432
enhancement: check for None instead
moritzrp Oct 5, 2024
67afc50
enhancement: don't sort the resulting defaults by keys
moritzrp Oct 5, 2024
85a5316
feat: add defaults_file option for defaults command
moritzrp Oct 5, 2024
d77e3e7
tests: add test case for generating defaults
moritzrp Oct 5, 2024
7dd1fe5
style: format file
moritzrp Oct 5, 2024
7a7ce9e
tests: add option without a default value
moritzrp Oct 5, 2024
bdfccee
refactor: change default style when dumping defaults
moritzrp Oct 6, 2024
a51b2d9
tests: add additional cases for types
moritzrp Oct 6, 2024
4cf91da
enhancement: add custom dumper to dump lists with indent
moritzrp Oct 6, 2024
1ede63f
tests: add truthy and umask string
moritzrp Oct 6, 2024
de10585
feat: exit defaults command early if no defaults configured
moritzrp Oct 6, 2024
23afb19
refactor: fix linting and formatting errors
moritzrp Oct 7, 2024
aac0f73
fix: handle case where no options are configured in argument_specs
moritzrp Oct 7, 2024
8409705
style: add docstring to test cases
moritzrp Oct 7, 2024
abf151f
refactor: restructure project
moritzrp Oct 7, 2024
b45abb7
refactor: defaults command use output_file option
moritzrp Oct 8, 2024
7919c24
Merge branch 'main' into feature/generate-defaults
rndmh3ro Oct 8, 2024
01e1d22
feat: add description comment to generated defaults
moritzrp Oct 9, 2024
99ef5f7
docs: add defaults information
moritzrp Oct 9, 2024
7e79e88
refactor: move overwrite up to manager class
moritzrp Oct 9, 2024
d178dd4
refactor: pass arguments instead of context
moritzrp Oct 9, 2024
9e65882
fix: dump truthy strings as strings
moritzrp Oct 9, 2024
7a042f5
refactor: bubble up exceptions
moritzrp Oct 9, 2024
07c1a76
Merge branch 'main' into feature/generate-defaults
rndmh3ro Oct 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ repos:
- jinja2
- typer
- pyyaml
- ruamel.yaml

- repo: https://github.com/pre-commit/mirrors-mypy.git
rev: v1.11.2
Expand Down
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# aar-doc - Automated Ansible Role Documentation

`aar-doc` is a tool for generating documentation automatically from an Ansible role's metadata. Specifically, it reads the `meta/main.yml` and `meta/argument_specs.yml` files.
`aar-doc` is a tool for generating documentation and defaults automatically from an Ansible role's metadata. Specifically, it reads the `meta/main.yml` and `meta/argument_specs.yml` files.

This is heavily inspired by [terraform-docs](https://github.com/terraform-docs/terraform-docs) which does a similar thing with Terraform modules. `aar-doc` isn't nearly as featureful though, but should do the trick!

Expand All @@ -18,7 +18,7 @@ pip install aar-doc

## Usage

```
```text
Usage: aar-doc [OPTIONS] ROLE_PATH COMMAND [ARGS]...

A tool for generating docs for Ansible roles.
Expand Down Expand Up @@ -46,16 +46,11 @@ pip install aar-doc
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ defaults Command for generating role defaults. │
│ markdown Command for generating role documentation in Markdown format. │
╰──────────────────────────────────────────────────────────────────────────────╯
```

### Modes

The `inject` mode will inject only the changed content in between the `BEGIN_ANSIBLE_DOCS` and `END_ANSIBLE_DOCS` markers. This makes it possible to have header and footer text in the file that is not touched. This is the default mode, and will revert to `replace` if the file does not exist to create it the first time.

The `replace` mode will replace the whole file with the template. Usually, the `inject` mode should be fine for regular usage and changing the mode is not necessary unless you want to overwrite an existing file.

### Configuration

The configuration options can be provided either via CLI arguments shown in `--help`, or a `--config-file` in YAML format. Note that the options have underscores when provided via the configuration file.
Expand All @@ -72,7 +67,23 @@ output_file: ROLE.md
output_mode: replace
```

### Templating
### Defaults

The defaults are written to the `defaults/main.yml` file in your provided role.

If you want to write them to a different file under `defaults/` you can specify that file via the `--output-file` option.

If your `argument_specs` contains an option with a default value multiple times, it will use the first found value and description by default. If you want the value and description to be overwritten, you can use the `--overwrite-duplicates` option.

### Markdown

#### Modes

The `inject` mode will inject only the changed content in between the `BEGIN_ANSIBLE_DOCS` and `END_ANSIBLE_DOCS` markers. This makes it possible to have header and footer text in the file that is not touched. This is the default mode, and will revert to `replace` if the file does not exist to create it the first time.

The `replace` mode will replace the whole file with the template. Usually, the `inject` mode should be fine for regular usage and changing the mode is not necessary unless you want to overwrite an existing file.

#### Templating

You can override the `--output-template` used for rendering the document. This may be passed in as a string containing Jinja2, or a path to a file. As noted above, this option may be passed in via CLI or the configuration file.

Expand Down Expand Up @@ -103,7 +114,7 @@ Template variables:

Example:

```
```jinja2
<!-- BEGIN_ANSIBLE_DOCS -->

This is my role: {{ role }}
Expand Down
Loading