diff options
author | Christoph Prokop <christoph.prokop@atos.net> | 2021-01-05 20:19:02 +0100 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-01-11 21:24:40 +0100 |
commit | a40013100f009dc5dceac2d89b73c08896780e74 (patch) | |
tree | 12e0d4cddffeb32a3dc4c668597d7ceaabed8c0e | |
parent | 5bb9b285d8c7b1071f955d0608fcc683c423ac31 (diff) |
Fix: Remove indentation from script snippets when building script
We actually need to make an ugly (and very bad performing) hack here, to
get the `unindent` crate to actually unindent here.
text = format!("\n{}", text).unindent(),
the format!() call is necessary to tell `unindent::Unindent::unindent()`
that the intended indentation is actually zero.
If we do not add that `\n` here, the first line of the to-be-unindented
indented text stays unintentionally indented.
For example, unindenting the intentionally indented string:
" intentionally indented
intentionally indented
"
results unintentionally in the partially indented and partially
unindented text:
" intentionally indented
intentionally indented
"
Which is not our intention of course, although it seems to be the
intention of the unindent crate, as documented.
But with the intentionally added `\n` we unindent the indentation of all
indented "intentionally indented" lines.
Signed-off-by: Christoph Prokop <christoph.prokop@atos.net>
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Tested-by: Christoph Prokop <christoph.prokop@atos.net>
Tested-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/package/script.rs | 7 |
2 files changed, 6 insertions, 2 deletions
@@ -45,6 +45,7 @@ terminal_size = "0.1" tokio = { version = "0.2", features = ["macros", "fs", "process", "io-util"] } toml = "0.5" typed-builder = "0.7" +unindent = "0.1" url = { version = "2", features = ["serde"] } uuid = { version = "0.6", features = ["serde", "v4"] } walkdir = "2" diff --git a/src/package/script.rs b/src/package/script.rs index 204d4c5..e8f34b9 100644 --- a/src/package/script.rs +++ b/src/package/script.rs @@ -156,13 +156,17 @@ impl<'a> ScriptBuilder<'a> { for name in phaseorder { match package.phases().get(name) { Some(Phase::Text(text)) => { + use unindent::Unindent; + script.push_str(&indoc::formatdoc!(r#" ### phase {} {} ### / {} phase "#, name.as_str(), - text, + // whack hack: insert empty line on top because unindent ignores the + // indentation of the first line, see commit message for more info + format!("\n{}", text).unindent(), name.as_str(), )); @@ -180,7 +184,6 @@ impl<'a> ScriptBuilder<'a> { "#, path = pb.display(), name = name.as_str())); - script.push_str("\n"); }, |