-
Notifications
You must be signed in to change notification settings - Fork 528
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -857,18 +857,38 @@ Helm includes the following regular expression functions: [regexFind | |||||||||||||||||||||||||||||
(mustRegexReplaceAllLiteral)](#regexreplaceallliteral-mustregexreplaceallliteral), | ||||||||||||||||||||||||||||||
[regexSplit (mustRegexSplit)](#regexsplit-mustregexsplit). | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
### regexMatch, mustRegexMatch | ||||||||||||||||||||||||||||||
### regexMatch | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||
{{- 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 | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
@@ -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 | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
Return the first (left most) match of the regular expression in the input string | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these references are going to be brittle
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: | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||
{{ regexFind "^abc$" "abcd" }} | ||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||
The above produces an empty string. | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
### regexReplaceAll, mustRegexReplaceAll | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
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.