Skip to content

Commit

Permalink
source/local: support comments in input
Browse files Browse the repository at this point in the history
Lines starting with '#' are treated as comments and ignored when parsing
feature files and hook output.
  • Loading branch information
marquiz committed Aug 4, 2023
1 parent 6d30ca9 commit 4aa7a8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/usage/customization-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,16 @@ The hook stdout and feature files are expected to contain features in simple
key-value pairs, separated by newlines:

```plaintext
# This is a comment
<name>[=<value>]
```

The label value defaults to `true`, if not specified.

Label namespace may be specified with `<namespace>/<name>[=<value>]`.

Comment lines (starting with `#`) are ignored.

### Mounts

The standard NFD deployments contain `hostPath` mounts for
Expand Down
5 changes: 5 additions & 0 deletions source/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ func parseFeatures(lines [][]byte) map[string]string {
for _, l := range lines {
line := strings.TrimSpace(string(l))
if len(line) > 0 {
// Skip comment lines
if strings.HasPrefix(line, "#") {
continue

Check warning on line 155 in source/local/local.go

View check run for this annotation

Codecov / codecov/patch

source/local/local.go#L153-L155

Added lines #L153 - L155 were not covered by tests
}

lineSplit := strings.SplitN(line, "=", 2)

key := lineSplit[0]
Expand Down

0 comments on commit 4aa7a8f

Please sign in to comment.