Use indoc for better raw text

This commit is contained in:
vh-zuka 2022-11-09 23:16:24 +07:00 committed by Lucas
parent 3faed5c980
commit 9d6f9fd013
3 changed files with 25 additions and 19 deletions

7
Cargo.lock generated
View File

@ -57,6 +57,7 @@ dependencies = [
"clap", "clap",
"hex", "hex",
"ignore", "ignore",
"indoc",
"miette", "miette",
"pallas-addresses", "pallas-addresses",
"pallas-codec", "pallas-codec",
@ -487,6 +488,12 @@ dependencies = [
"hashbrown", "hashbrown",
] ]
[[package]]
name = "indoc"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adab1eaa3408fb7f0c777a73e7465fd5656136fc93b670eb6df3c88c2c1344e3"
[[package]] [[package]]
name = "instant" name = "instant"
version = "0.1.12" version = "0.1.12"

View File

@ -13,6 +13,7 @@ anyhow = "1.0.57"
clap = { version = "3.1.14", features = ["derive"] } clap = { version = "3.1.14", features = ["derive"] }
hex = "0.4.3" hex = "0.4.3"
ignore = "0.4.18" ignore = "0.4.18"
indoc = "1.0"
miette = { version = "5.3.0", features = ["fancy"] } miette = { version = "5.3.0", features = ["fancy"] }
pallas-addresses = "0.14.0" pallas-addresses = "0.14.0"
pallas-codec = "0.14.0" pallas-codec = "0.14.0"

View File

@ -1,3 +1,4 @@
use indoc::{formatdoc, indoc};
use miette::IntoDiagnostic; use miette::IntoDiagnostic;
use std::fs; use std::fs;
use std::io::Write; use std::io::Write;
@ -24,7 +25,7 @@ impl Creator {
Self { Self {
root, root,
src, src,
project_name project_name,
} }
} }
@ -40,30 +41,28 @@ impl Creator {
fn always_true_script(&self) -> miette::Result<()> { fn always_true_script(&self) -> miette::Result<()> {
write( write(
self.src.join("always_true.ak"), self.src.join("always_true.ak"),
" indoc! {"
pub fn spend() -> Bool { pub fn spend() -> Bool {
true true
} }
" "},
) )
} }
fn aiken_toml(&self) -> miette::Result<()> { fn aiken_toml(&self) -> miette::Result<()> {
write( write(
self.root.join("aiken.toml"), self.root.join("aiken.toml"),
&format!( &formatdoc! {
r#"name = "{name}" r#"name = "{name}"
version = "0.1.0" version = "0.1.0"
licences = ["Apache-2.0"] licences = ["Apache-2.0"]
description = "Aiken contracts" description = "Aiken contracts"
[dependencies] [dependencies]
aiken = "~> {aiken}"
"#, "#,
name = self.project_name, name = self.project_name,
aiken = "0.0.24", },
),
) )
} }
} }
@ -72,7 +71,6 @@ fn write(path: PathBuf, contents: &str) -> miette::Result<()> {
let mut f = fs::File::create(&path).into_diagnostic()?; let mut f = fs::File::create(&path).into_diagnostic()?;
f.write_all(contents.as_bytes()).into_diagnostic()?; f.write_all(contents.as_bytes()).into_diagnostic()?;
Ok(()) Ok(())
} }