Add --watch flag to the 'build' and 'docs' commands too.

This commit is contained in:
KtorZ 2023-11-25 14:52:51 +01:00
parent 7645a9460f
commit 40c0fa7d77
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 28 additions and 6 deletions

View File

@ -1,4 +1,4 @@
use aiken_project::watch::with_project; use aiken_project::watch::{self, watch_project, with_project};
use std::path::PathBuf; use std::path::PathBuf;
#[derive(clap::Args)] #[derive(clap::Args)]
@ -11,6 +11,10 @@ pub struct Args {
#[clap(short = 'D', long)] #[clap(short = 'D', long)]
deny: bool, deny: bool,
/// When enabled, re-run the command on file changes instead of exiting
#[clap(short, long)]
watch: bool,
/// Also dump textual uplc /// Also dump textual uplc
#[clap(short, long)] #[clap(short, long)]
uplc: bool, uplc: bool,
@ -24,11 +28,18 @@ pub fn exec(
Args { Args {
directory, directory,
deny, deny,
watch,
uplc, uplc,
keep_traces, keep_traces,
}: Args, }: Args,
) -> miette::Result<()> { ) -> miette::Result<()> {
if watch {
watch_project(directory.as_deref(), watch::default_filter, 500, |p| {
p.build(uplc, keep_traces.into())
})
} else {
with_project(directory.as_deref(), deny, |p| { with_project(directory.as_deref(), deny, |p| {
p.build(uplc, keep_traces.into()) p.build(uplc, keep_traces.into())
}) })
} }
}

View File

@ -1,4 +1,4 @@
use aiken_project::watch::with_project; use aiken_project::watch::{self, watch_project, with_project};
use std::path::PathBuf; use std::path::PathBuf;
#[derive(clap::Args)] #[derive(clap::Args)]
@ -11,6 +11,10 @@ pub struct Args {
#[clap(short = 'D', long)] #[clap(short = 'D', long)]
deny: bool, deny: bool,
/// When enabled, re-run the command on file changes instead of exiting
#[clap(short, long)]
watch: bool,
/// Output directory for the documentation /// Output directory for the documentation
#[clap(short = 'o', long)] #[clap(short = 'o', long)]
destination: Option<PathBuf>, destination: Option<PathBuf>,
@ -20,8 +24,15 @@ pub fn exec(
Args { Args {
directory, directory,
deny, deny,
watch,
destination, destination,
}: Args, }: Args,
) -> miette::Result<()> { ) -> miette::Result<()> {
if watch {
watch_project(directory.as_deref(), watch::default_filter, 500, |p| {
p.docs(destination.clone())
})
} else {
with_project(directory.as_deref(), deny, |p| p.docs(destination.clone())) with_project(directory.as_deref(), deny, |p| p.docs(destination.clone()))
} }
}