use super::*;
#[derive(Parser, Debug)]
pub struct LeoFormat {
#[clap(flatten)]
args: leo_fmt::FormatCliArgs,
}
impl Command for LeoFormat {
type Input = ();
type Output = ();
fn log_span(&self) -> Span {
tracing::span!(tracing::Level::INFO, "Leo")
}
fn prelude(&self, _: Context) -> Result<Self::Input> {
Ok(())
}
fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
let LeoFormat { args } = self;
let base_dir = context.dir()?;
let has_unformatted = leo_fmt::run_format_cli(&args, &base_dir).map_err(|error| -> leo_errors::LeoError {
if error.kind() == std::io::ErrorKind::InvalidInput {
CliError::cli_invalid_input(error).into()
} else {
CliError::cli_io_error(error).into()
}
})?;
if args.check && has_unformatted {
std::process::exit(1);
}
Ok(())
}
}