Add support for json output format#49
Add support for json output format#49g4s8 merged 3 commits intog4s8:masterfrom rodionstolyarov:json-format
Conversation
g4s8
left a comment
There was a problem hiding this comment.
Thanks for contribution! Please check one comment above. Also, please add an example to _examples/ with json output, and build it using _examples/build-examples.sh.
render/templates.go
Outdated
| return sum | ||
| }, | ||
| "marshal": func(v any) string { | ||
| a, _ := json.Marshal(v) |
There was a problem hiding this comment.
Looks like here a fatal error can occur. We need to panic here and recover on render caller.
There was a problem hiding this comment.
I think we can return an error along with string result instead of panic.
- add an example for json format - update marshal function to return an error
|
Thanks for your feedback! I've added json format to |
g4s8
left a comment
There was a problem hiding this comment.
Thanks, it looks good. Could you check please some comments with questions?
_examples/simple/doc.json
Outdated
| @@ -0,0 +1 @@ | |||
| [{"env_name":"HOST","doc":"Hosts name of hosts to listen on.","env_default":"","env_separator":";","required":true,"expand":false,"non_empty":false,"from_file":false},{"env_name":"PORT","doc":"Port to listen on.","env_default":"","env_separator":"","required":true,"expand":false,"non_empty":true,"from_file":false},{"env_name":"DEBUG","doc":"Debug mode enabled.","env_default":"false","env_separator":"","required":false,"expand":false,"non_empty":false,"from_file":false},{"env_name":"PREFIX","doc":"Prefix for something.","env_default":"","env_separator":"","required":false,"expand":false,"non_empty":false,"from_file":false}] | |||
There was a problem hiding this comment.
I think it could be more readable with indentations (it could be set in json encoder), it seems here we don't need size optimization, since the size of the documentation can't be big enough.
And what do you think about omitting empty fields? E.g. envDefault and envSeparator?
There was a problem hiding this comment.
That makes sense. I've added omitempty tag for all bool fields as well.
Sometimes it needs to export documentation for envs in JSON format for further automation.
This PR supports a new output format
json.