Add e substitution flag#413
Conversation
|
please run rustfmt |
| // Execute the pattern space as a shell command if the 'e' flag is set | ||
| if sub.execute { | ||
| let cmd_str = pattern.as_str()?.to_string(); | ||
| let output_bytes = std::process::Command::new("/bin/sh") |
There was a problem hiding this comment.
/bin/sh ?
it won't work on windows
There was a problem hiding this comment.
Should I make it conditionally compile on UNIX-like system only and warn out the insufficient capabilities on Windows, or do I instead execute the cmd.exe for Windows? The latter one would still require conditional compilation, so i can add #[cfg] for UNIX-like and Windows.
There was a problem hiding this comment.
nope, it is a cross platform project. this should be a tier-1 feature on Windows too
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #413 +/- ##
==========================================
+ Coverage 82.20% 82.72% +0.51%
==========================================
Files 13 13
Lines 5542 5545 +3
Branches 310 307 -3
==========================================
+ Hits 4556 4587 +31
+ Misses 983 955 -28
Partials 3 3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
please also add tests in tests/by-util/test_sed.rs |
|
Thanks for the guidance, will work into it. |
e subsitutione substitution
Introduce the 'e' flag for the substitution command, which pipes the pattern space through a shell and replaces it with the output. - Add shell_command() with platform-specific implementations (sh on Unix, cmd on Windows) - Handle WASM gracefully with a fallback - Trim trailing newlines accounting for Windows line endings - Add tests for the new flag, with conditional compilation for platform-specific behavior Signed-off-by: PranavRJoshi <pranavrjoshi1@gmail.com>
This PR introduces
esubstitution mentioned in #404.What this does
Implements the
esubstitute flag, which executes the result of the substitution as a shell command and replaces the pattern space with stdout (minus trailing newline).Changes
src/sed/command.rs: newexecute: boolfield onSubstitutionsrc/sed/compiler.rs:'e'arm incompile_subst_flags; rejected at compile time under--posixor--sandbox.src/sed/processor.rs: shell execution via/bin/sh -cafter substitutionTests
cargo testrun passes.