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

View File

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

View File

@ -1,3 +1,4 @@
use indoc::{formatdoc, indoc};
use miette::IntoDiagnostic;
use std::fs;
use std::io::Write;
@ -21,10 +22,10 @@ impl Creator {
let root = args.name;
let src = root.join("src");
let project_name = root.clone().into_os_string().into_string().unwrap();
Self{
Self {
root,
src,
project_name
project_name,
}
}
@ -39,31 +40,29 @@ impl Creator {
fn always_true_script(&self) -> miette::Result<()> {
write(
self.src.join("always_true.ak"),
"
pub fn spend() -> Bool {
true
}
"
self.src.join("always_true.ak"),
indoc! {"
pub fn spend() -> Bool {
true
}
"},
)
}
fn aiken_toml(&self) -> miette::Result<()> {
write(
self.root.join("aiken.toml"),
&format!(
&formatdoc! {
r#"name = "{name}"
version = "0.1.0"
licences = ["Apache-2.0"]
description = "Aiken contracts"
version = "0.1.0"
licences = ["Apache-2.0"]
description = "Aiken contracts"
[dependencies]
aiken = "~> {aiken}"
[dependencies]
"#,
"#,
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()?;
f.write_all(contents.as_bytes()).into_diagnostic()?;
Ok(())
}
@ -80,7 +78,7 @@ pub fn exec(args: Args) -> miette::Result<()> {
if !args.name.exists() {
let creator = Creator::new(args);
creator.run()?;
}
}
Ok(())
}