Skip to content

Commit a625714

Browse files
Merge pull request #33 from inteon/add_hidden_option
Add tag `+docs:hidden` to hide field from docs only
2 parents 76d3001 + de5a850 commit a625714

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ Tags are used to alter how the documentation is generated. They are comments tha
8888

8989
- `+docs:section=<name>` - Creates a new documentation section
9090
- `+docs:property` - Marks the field as a property that needs documentation
91-
- `+docs:ignore` - Ignore the field, not generating documentation
91+
- `+docs:ignore` - Ignore the field, not generating documentation, not used for linting or json schema generation
92+
- `+docs:hidden` - Hide the field from the documentation, but still use it for linting and json schema generation
9293
- `+docs:type=<type>` - Override the type information for the property
9394
- `+docs:default=<default>` - Override the default value for the property
9495

main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var Render = cobra.Command{
4646
Use: "render",
4747
Short: "render documentation to stdout",
4848
Run: func(cmd *cobra.Command, args []string) {
49-
document, err := parser.Load(valuesFile)
49+
document, err := parser.Load(valuesFile, false)
5050
if err != nil {
5151
fmt.Fprintf(os.Stderr, "Could not open %q: %s\n", valuesFile, err)
5252
os.Exit(1)
@@ -66,7 +66,7 @@ var Inject = cobra.Command{
6666
Use: "inject",
6767
Short: "generate documentation and inject into existing markdown file",
6868
Run: func(cmd *cobra.Command, args []string) {
69-
document, err := parser.Load(valuesFile)
69+
document, err := parser.Load(valuesFile, false)
7070
if err != nil {
7171
fmt.Fprintf(os.Stderr, "Could not open %q: %s\n", valuesFile, err)
7272
os.Exit(1)
@@ -82,7 +82,7 @@ var Inject = cobra.Command{
8282
var Schema = cobra.Command{
8383
Use: "schema",
8484
Run: func(cmd *cobra.Command, args []string) {
85-
document, err := parser.Load(valuesFile)
85+
document, err := parser.Load(valuesFile, true)
8686
if err != nil {
8787
fmt.Fprintf(os.Stderr, "Could not open %q: %s\n", valuesFile, err)
8888
os.Exit(1)
@@ -101,7 +101,7 @@ var Schema = cobra.Command{
101101
var Lint = cobra.Command{
102102
Use: "lint",
103103
Run: func(cmd *cobra.Command, args []string) {
104-
document, err := parser.Load(valuesFile)
104+
document, err := parser.Load(valuesFile, true)
105105
if err != nil {
106106
fmt.Fprintf(os.Stderr, "Could not open %q: %s\n", valuesFile, err)
107107
os.Exit(1)

parser/document.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
const (
3030
TagSection = "docs:section"
3131
TagIgnore = "docs:ignore"
32+
TagHidden = "docs:hidden"
3233
TagType = "docs:type"
3334
TagDefault = "docs:default"
3435
TagProperty = "docs:property"
@@ -90,7 +91,7 @@ type Node struct {
9091
RawNode *yaml.Node
9192
}
9293

93-
func Load(filename string) (*Document, error) {
94+
func Load(filename string, includeHidden bool) (*Document, error) {
9495
file, err := os.Open(filename)
9596
if err != nil {
9697
return nil, err
@@ -118,6 +119,11 @@ func Load(filename string) (*Document, error) {
118119
return true, nil
119120
}
120121

122+
// If we have a comment instructing us to hide this node, obey it if we are not including hidden nodes
123+
if comment.Tags.GetBool(TagHidden) && !includeHidden {
124+
return true, nil
125+
}
126+
121127
// An end node is a node we find a property at, this is usually a scalar
122128
// node, but can be a map or sequence if the user uses the
123129
// +docs:property tag (or if they have no values).

0 commit comments

Comments
 (0)