Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type Config struct {
* `-types` (glob string, *optional*) - Type glob pattern for type names to process. If not specified, the next type after `go:generate` is used.
* `-target` (`enum(caarlos0, cleanenv)` string, optional, default `caarlos0`) - Set env library target.
* `-output` (path string, **required**) - Output file name for generated documentation.
* `-format` (`enum(markdown, plaintext, html, dotenv, json)` string, *optional*) - Output format for documentation. Default is `markdown`.
* `-format` (`enum(markdown, plaintext, html, dotenv, dotenv.dist, json)` string, *optional*) - Output format for documentation. Default is `markdown`.
* `-no-styles` (`bool`, *optional*) - If true, CSS styles will not be included for `html` format.
* `-env-prefix` (`string`, *optional*) - Sets additional global prefix for all environment variables.
* `-tag-name` (string, *optional*, default: `env`) - Use custom tag name instead of `env`.
Expand Down
1 change: 1 addition & 0 deletions _examples/simple/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package main
//go:generate go run ../../ -output doc.md -format markdown
//go:generate go run ../../ -output doc.html -format html
//go:generate go run ../../ -output doc.env -format dotenv
//go:generate go run ../../ -output doc.env.dist -format dotenv.dist
//go:generate go run ../../ -output doc.json -format json
type Config struct {
// Hosts name of hosts to listen on.
Expand Down
8 changes: 4 additions & 4 deletions _examples/simple/doc.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#
## Hosts name of hosts to listen on.
## (separated by ';', required)
# HOST=""
HOST=""
## Port to listen on.
## (required, non-empty)
# PORT=""
PORT=""
## Debug mode enabled.
## (default: 'false')
# DEBUG="false"
DEBUG="false"
## Prefix for something.
# PREFIX=""
PREFIX=""

20 changes: 20 additions & 0 deletions _examples/simple/doc.env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Environment Variables


## Config
## Config is an example configuration structure.
## It is used to generate documentation for the configuration
## using the commands below.
#
# Hosts name of hosts to listen on.
# (separated by ';', required)
HOST=<FIXME>
# Port to listen on.
# (required, non-empty)
PORT=<FIXME>
# Debug mode enabled.
# (default: 'false')
DEBUG="false"
# Prefix for something.
PREFIX=<FIXME>

12 changes: 12 additions & 0 deletions render/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ var configs = map[types.OutFormat]renderConfig{
},
tmpl: newTmplText("dotenv.tmpl"),
},
types.OutFormatEnvDist: {
Item: renderItemConfig{
SeparatorFormat: "separated by '%s'",
SeparatorDefault: "comma-separated",
OptRequired: "required",
OptExpand: "expand",
OptFromFile: "from-file",
OptNonEmpty: "non-empty",
EnvDefaultFormat: "default: '%s'",
},
tmpl: newTmplText("dotenvdist.tmpl"),
},
types.OutFormatJSON: {
Item: renderItemConfig{},
tmpl: newTmplText("json.tmpl"),
Expand Down
4 changes: 2 additions & 2 deletions render/templ/dotenv.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
{{- end }}
{{- template "item.options" (list $ $cfg "## (%s)\n") }}
{{- if $.EnvDefault }}
{{- printf `# %s="%s"` $.EnvName $.EnvDefault }}
{{- printf `%s="%s"` $.EnvName $.EnvDefault }}
{{- else }}
{{- printf `# %s=""` $.EnvName }}
{{- printf `%s=""` $.EnvName }}
{{- end }}
{{- end }}
{{- $children := $.Children 0 }}
Expand Down
41 changes: 41 additions & 0 deletions render/templ/dotenvdist.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{- define "item" }}
{{- $ := index . 0 }}
{{- $cfg := index . 1 }}
{{- if eq $.EnvName "" }}
#
{{- end }}
{{- template "doc.lines" (list $.Doc "#") }}
{{- if $.EnvName }}
{{- if $.Doc }}
{{- printf "\n" }}
{{- end }}
{{- template "item.options" (list $ $cfg "# (%s)\n") }}
{{- if $.EnvDefault }}
{{- printf `%s="%s"` $.EnvName $.EnvDefault }}
{{- else }}
{{- printf `%s="<FIXME>"` $.EnvName }}
{{- end }}
{{- end }}
{{- $children := $.Children 0 }}
{{- if $children }}
#
{{- range $child := $children }}
{{- template "item" (list $child $cfg) }}
{{- end }}
{{- end }}
{{- end -}}

{{- $cfg := $.Config -}}
# {{ .Title }}
{{ range .Sections }}
{{- print "\n" }}
{{- if .Name }}
## {{ .Name }}
{{- end }}
{{- template "doc.lines" (list .Doc "##") }}
#
{{- range $item := .Items }}
{{- template "item" (list $item $cfg.Item) }}
{{- end }}
{{- end }}

1 change: 1 addition & 0 deletions types/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
OutFormatHTML OutFormat = "html"
OutFormatTxt OutFormat = "plaintext"
OutFormatEnv OutFormat = "dotenv"
OutFormatEnvDist OutFormat = "dotenv.dist"
OutFormatJSON OutFormat = "json"
)

Expand Down