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

fix(30216): Add more docs for must version of functions #1698

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
45 changes: 36 additions & 9 deletions content/en/docs/chart_template_guide/function_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -857,18 +857,38 @@ Helm includes the following regular expression functions: [regexFind
(mustRegexReplaceAllLiteral)](#regexreplaceallliteral-mustregexreplaceallliteral),
[regexSplit (mustRegexSplit)](#regexsplit-mustregexsplit).

### regexMatch, mustRegexMatch
### regexMatch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are links above and this change breaks that. I don't think you should change the headers or add the ### mustRegexMatch header here.


Returns true if the input string contains any match of the regular expression.
Returns `true` if the input string contains any match of the regular expression.

```
regexMatch "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$" "[email protected]"
{{- if regexMatch "^abc$" "abc" -}}
valid: true
{{- end -}}
```
The above produces `valid: true`.

The above produces `true`
`regexMatch` will ignore regex compilation errors, and simply return `false` ([ref](https://github.com/Masterminds/sprig/blob/master/regex.go#L7))

```
{{- if regexMatch "[" "abc" -}}
valid: true
{{- end -}}
```
The above produces nothing.

### mustRegexMatch

Similar to `regexMatch`, but will return an error to the templating engine if the regex fails to compile:
Comment on lines +871 to +882
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`regexMatch` will ignore regex compilation errors, and simply return `false` ([ref](https://github.com/Masterminds/sprig/blob/master/regex.go#L7))
```
{{- if regexMatch "[" "abc" -}}
valid: true
{{- end -}}
```
The above produces nothing.
### mustRegexMatch
Similar to `regexMatch`, but will return an error to the templating engine if the regex fails to compile:
In the event of regex compilation errors, `regexMatch` will simply return `false`.
Use `mustRegexMatch` to fail in the event of regex compilation errors.


```
{{- if mustRegexMatch "[" "abc" -}}
valid: true
{{- end -}}
```

The above produces `error: "error parsing regexp: missing closing ]`.

`regexMatch` panics if there is a problem and `mustRegexMatch` returns an error
to the template engine if there is a problem.

### regexFindAll, mustRegexFindAll

Expand All @@ -885,7 +905,7 @@ The above produces `[2 4 6 8]`
`regexFindAll` panics if there is a problem and `mustRegexFindAll` returns an
error to the template engine if there is a problem.

### regexFind, mustRegexFind
### regexFind
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### regexFind
### regexFind, mustRegexFind


Return the first (left most) match of the regular expression in the input string

Expand All @@ -895,8 +915,15 @@ regexFind "[a-zA-Z][1-9]" "abcd1234"

The above produces `d1`

`regexFind` panics if there is a problem and `mustRegexFind` returns an error to
the template engine if there is a problem.
`regexFind` will result in a panic if the regex fails to compile ([ref](https://github.com/Masterminds/sprig/blob/master/regex.go#L30)), whereas
`mustRegexFind` will return an error to the templating engine if the regex fails to compile ([ref](https://github.com/Masterminds/sprig/blob/master/regex.go#L34)).
Comment on lines +918 to +919
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these references are going to be brittle

Suggested change
`regexFind` will result in a panic if the regex fails to compile ([ref](https://github.com/Masterminds/sprig/blob/master/regex.go#L30)), whereas
`mustRegexFind` will return an error to the templating engine if the regex fails to compile ([ref](https://github.com/Masterminds/sprig/blob/master/regex.go#L34)).
The `regexFind` function will result in a panic if the regex fails to compile, whereas
`mustRegexFind` will return an error to the templating engine if the regex fails to compile.


Note that neither function will panic/return an error if the input string does not match the regex. Both functions return an empty string in this case:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project doesn't strictly use semantic line breaks, but I think it helps.

Suggested change
Note that neither function will panic/return an error if the input string does not match the regex. Both functions return an empty string in this case:
Note that neither function will panic/return an error if the input string does not match the regex.
Both functions return an empty string in this case:


```
{{ regexFind "^abc$" "abcd" }}
```
The above produces an empty string.

### regexReplaceAll, mustRegexReplaceAll

Expand Down