-
Notifications
You must be signed in to change notification settings - Fork 824
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
feat(cli) Improve environment variables parsing #2042
Conversation
The following environment variables are considered incorrect: * `A`, no equal sign, * `A=`, value is missing, * `=A`, key is missing. The following environment variables are considered correct: * `A=B` with `A` for the name and `B` for the value, * `A=B=C` with `A` for the name and `B=C` for the value.
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.
Looks good , thanks for the tests!
&entry | ||
), | ||
|
||
Some(position) => Ok((entry[..position].into(), entry[position + 1..].into())), |
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.
The actual splitting can just be done with just https://doc.rust-lang.org/std/primitive.str.html#method.split_at ; but we won't have as many error cases to report.
Just a heads up, I'm fine keeping it as-is
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.
We would need to deal with empty string for the left- or right-end side of the =
. I think the code would not be simplified that much. Thanks for the heads-up!
bors r+ |
Description
This PR fixes #2028. In #1762 we have already improved environment variables syntax, but the same work must be done in the CLI crate.
The following environment variables are considered incorrect:
A
, no equal sign,A=
, value is missing,=A
, key is missing.The following environment variables are considered correct:
A=B
withA
for the name andB
for the value,A=B=C
withA
for the name andB=C
for the value.The environment variable is trimmed before being parsed with
str::trim
.This PR also adds tests for the
parse_envvar
function, which was missing.Review