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

expression documentation needs more information #220

Closed
brucejo75 opened this issue Mar 17, 2022 · 7 comments
Closed

expression documentation needs more information #220

brucejo75 opened this issue Mar 17, 2022 · 7 comments

Comments

@brucejo75
Copy link
Contributor

brucejo75 commented Mar 17, 2022

Moved from https://github.com/caddyserver/caddy/issues/4641


Going through my monthly hair tear out trying to program my Caddyfile discovered how expressions need to be formatted.

Examples here are either misleading or incomplete. None of these examples put the expression within a string.

When looking through the forums everyone encloses their expressions within a string.

Without enclosing in a string my expression did not work.

bad: @myNamedMatcher expression {my_placeholder} == "0"
good: @myNamedMatcher expression `{my_placeholder} == "0"`

Request: please update the documentation with examples that enclose the expressions within strings and explain when/why enclosing strings are needed.

Thanks!

@mholt
Copy link
Member

mholt commented Mar 17, 2022

Not many people use the expression matcher (that we know of) -- and it's still experimental. Sorry if the documentation is not quite accurate.

@francislavoie I haven't looked recently, but I assume we are thinking the entire expr will be in a single token. We could either do a join() on the remaining args assuming that the whole line is an expression, or continue to require the entire expression in a single token (but then our docs are wrong). What do you think we should do? I'm leaning toward the join() solution since it avoids having to wrap an expression that might use quotes in strings.

@brucejo75
Copy link
Contributor Author

My opinion: just document it as-is. It works great when you know that. Work on the bigger fish.

@brucejo75
Copy link
Contributor Author

PS: expression matcher is excellent!

@francislavoie
Copy link
Member

francislavoie commented Mar 18, 2022

Actually we do a join @mholt but the issue is that since " has a meaning in the Caddyfile as a string delimiter (the Caddyfile parser looks at each token before dispensing them), the expression as parsed by Caddy becomes {my_placeholder} == 0 i.e. the number 0 instead of the string "0". And I think comparing as the wrong type fails. (As an aside it would be possible to cast the number to a string and not use any ")

But yeah we can improve the docs for sure.

@mholt
Copy link
Member

mholt commented Mar 18, 2022

@francislavoie Ah, thanks for reminding me 🤦‍♂️ Yeah... I mean, the docs do talk about tokens and parsing, but maybe we could clarify strings a bit around the expression matcher.

@mholt
Copy link
Member

mholt commented Mar 18, 2022

Ok we got this improved in caddyserver/caddy#4643. Thanks Francis!

@mholt mholt closed this as completed Mar 18, 2022
@brucejo75
Copy link
Contributor Author

Wow! OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants