use crate::with_project;
use aiken_lang::ast::Tracing;
use std::path::PathBuf;
#[derive(clap::Args)]
#[clap(setting(clap::AppSettings::DeriveDisplayOrder))]
pub struct Args {
directory: Option<PathBuf>,
#[clap(short, long)]
module: Option<String>,
#[clap(short, long)]
validator: Option<String>,
#[clap(long)]
delegated_to: Option<String>,
#[clap(long)]
rebuild: bool,
}
pub fn exec(
Args {
directory,
module,
validator,
delegated_to,
rebuild,
}: Args,
) -> miette::Result<()> {
with_project(directory, |p| {
if rebuild {
p.build(false, Tracing::NoTraces)?;
}
let title = module.as_ref().map(|m| {
format!(
"{m}{}",
validator
.as_ref()
.map(|v| format!(".{v}"))
.unwrap_or_default()
)
});
let title = title.as_ref().or(validator.as_ref());
let address = p.address(title, delegated_to.as_ref())?;
println!("{}", address.to_bech32().unwrap());
Ok(())
})
}