-
Notifications
You must be signed in to change notification settings - Fork 1
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
Support substring and replacement #8 #9
Conversation
"Substring Expansion" is a bash'ism to extract slices from a string in the form of: ${parameter:offset} ${parameter:offset:length} This is a minimal implementation that only supports simple slices on strings and does not support arrays See https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Replacing with "/" is a bash'ism to replace a pattern with a string in the parameter being expanded with the form of: ${parameter/pattern/string} This is a simple and minimal implementation: - supports only plain strings patterns (and not actual glob patterns). - does not handle #, %, @ and * pattern modifiers. See https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Using expand(env=None) was failing as the os module was not imported Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
This performs a simple expansion for plain $parameters (without curly braces) and is done as a pre-processing step in expand(). This also allows for some minimal level of parameter nesting as a $parameter can be nested in a ${parameter}. Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
for more information, see https://pre-commit.ci
Also update module documentation Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
fix #191 Signed-off-by: Mateusz Perc <m.perc@samsung.com>
Note that I have tried to keep each commit mostly self-standing if you want to cherry pick some |
simple_test_cases = { | ||
# string, env, result | ||
"-${parameter/$aa/$bb}-": ( | ||
dict( |
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.
Why dict()
instead of a literal dict?
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.
I feel it makes it stand out more clearly as being a mapping of environment variables... but I am fine either way
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.
Very nice, thanks. I am approving this as-is. You can implement my additional suggestions, or just merge as-is.
Leaving off the final slash is valid in a substitution as in: $ parameter=aa/bb/cc; echo "-${parameter/aa}-" -/bb/cc- Reported-by: Michael A. Smith <michael@smith-li.com> Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Thank you for the swift merge. |
This PR adds minimal support for some Bash idioms for #8
In addition:
some simple nesting.
Signed-off-by: Philippe Ombredanne pombredanne@nexb.com