feat: bring over the formatter from gleam
This commit is contained in:
31
crates/cli/src/cmd/fmt.rs
Normal file
31
crates/cli/src/cmd/fmt.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
#[derive(clap::Args)]
|
||||
/// Create a new Aiken project
|
||||
pub struct Args {
|
||||
/// Files to format
|
||||
#[clap(default_value = ".")]
|
||||
files: Vec<String>,
|
||||
|
||||
/// Read source from STDIN
|
||||
#[clap(long)]
|
||||
stdin: bool,
|
||||
|
||||
/// Check if inputs are formatted without changing them
|
||||
#[clap(long)]
|
||||
check: bool,
|
||||
}
|
||||
|
||||
pub fn exec(
|
||||
Args {
|
||||
check,
|
||||
stdin,
|
||||
files,
|
||||
}: Args,
|
||||
) -> miette::Result<()> {
|
||||
if let Err(err) = aiken_project::format::run(stdin, check, files) {
|
||||
err.report();
|
||||
|
||||
miette::bail!("failed: {} error(s)", err.total());
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod build;
|
||||
pub mod check;
|
||||
pub mod fmt;
|
||||
pub mod new;
|
||||
pub mod tx;
|
||||
pub mod uplc;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use aiken::cmd::{build, check, new, tx, uplc};
|
||||
use aiken::cmd::{build, check, fmt, new, tx, uplc};
|
||||
use clap::Parser;
|
||||
|
||||
/// Aiken: a smart-contract language and toolchain for Cardano
|
||||
@@ -8,6 +8,7 @@ use clap::Parser;
|
||||
#[clap(setting(clap::AppSettings::DeriveDisplayOrder))]
|
||||
pub enum Cmd {
|
||||
New(new::Args),
|
||||
Fmt(fmt::Args),
|
||||
Build(build::Args),
|
||||
Check(check::Args),
|
||||
|
||||
@@ -28,6 +29,7 @@ fn main() -> miette::Result<()> {
|
||||
miette::set_panic_hook();
|
||||
match Cmd::default() {
|
||||
Cmd::New(args) => new::exec(args),
|
||||
Cmd::Fmt(args) => fmt::exec(args),
|
||||
Cmd::Build(args) => build::exec(args),
|
||||
Cmd::Check(args) => check::exec(args),
|
||||
Cmd::Tx(sub_cmd) => tx::exec(sub_cmd),
|
||||
|
||||
Reference in New Issue
Block a user