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

Investigate different method of template replacement instead of $-prefixed #239

Open
Breakthrough opened this issue Sep 4, 2021 · 3 comments

Comments

@Breakthrough
Copy link
Owner

Breakthrough commented Sep 4, 2021

Description of Problem & Solution
Right now using templates in bash requires escaping the dollar signs. Investigate using a style similar to Python instead to help with this, e.g.:

scenedetect [...] split-video -f {VIDEO_NAME}-Scene-{SCENE_NUMBER}.mp4

Proposed Implementation:
Allow both dollar signed template $VARIABLES as well as braced {VARIABLES} to mean the same thing. However since {} may need to be escaped (see below), another solution might need to be investigated.

If any best practices exist, those should be followed.

Alternative Solutions:
TODO: Research how most other command line interfaces approach this before finalizing a solution.

@Breakthrough Breakthrough changed the title Accept braced templates instead of dollar-sign prefixed Accept braced templates in addition to dollar-sign prefixed Sep 4, 2021
@Breakthrough Breakthrough added this to the v0.5.7 milestone Sep 4, 2021
@Breakthrough
Copy link
Owner Author

Breakthrough commented Nov 3, 2021

Apparently braces need to be escaped in bash terminals as well, so might need to just use another delimiter symbol. I'm unable to find any documented best practices involving command line arguments specifically for string/template replacement, so any resources someone can point me to would be much appreciated.

@Breakthrough Breakthrough changed the title Accept braced templates in addition to dollar-sign prefixed Investigate different method of template replacement instead of $-prefixed Nov 3, 2021
@Breakthrough Breakthrough modified the milestones: v0.6, v1.0 Feb 12, 2022
@Breakthrough
Copy link
Owner Author

As found in #291, there also might be issues with only using a prefix, so using a suffix should be considered.

@wjs018
Copy link
Collaborator

wjs018 commented Oct 28, 2022

I was doing some reading on the python Template class and found out why the behavior identified in #291 occurs. See here for an explanation (tl;dr is that _ is a reserved python character and can break substitution unless braces are also used). For example '$VIDEO_NAME_test.csv' does not work because the variable is followed by _. However, '${VIDEO_NAME}_test.csv' does work because the brackets separate the template variable from the _.

If changing the delimiter is desired, then creating a custom template class that inherits from Template and then rewriting the delimiter might be a good way to go. Template doesn't seem to support a prefix/suffix substitution scheme that I can tell, so this kind of issue with a template variable being followed by a reserved python character would require a different solution (regex substitution?).

Alternatively, this edge case could be documented in the docs with the solution of including braces. Or, the documentation could include braces in all cases and the inclusion of braces is essentially considered the "default" usage.

@Breakthrough Breakthrough removed this from the v1.0 milestone Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants