From 40c0fa7d77f8940b4dbb6f1c0f7013b647961baa Mon Sep 17 00:00:00 2001 From: KtorZ Date: Sat, 25 Nov 2023 14:52:51 +0100 Subject: [PATCH] Add --watch flag to the 'build' and 'docs' commands too. --- crates/aiken/src/cmd/build.rs | 19 +++++++++++++++---- crates/aiken/src/cmd/docs.rs | 15 +++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/crates/aiken/src/cmd/build.rs b/crates/aiken/src/cmd/build.rs index 92007a6a..4067ab9e 100644 --- a/crates/aiken/src/cmd/build.rs +++ b/crates/aiken/src/cmd/build.rs @@ -1,4 +1,4 @@ -use aiken_project::watch::with_project; +use aiken_project::watch::{self, watch_project, with_project}; use std::path::PathBuf; #[derive(clap::Args)] @@ -11,6 +11,10 @@ pub struct Args { #[clap(short = 'D', long)] deny: bool, + /// When enabled, re-run the command on file changes instead of exiting + #[clap(short, long)] + watch: bool, + /// Also dump textual uplc #[clap(short, long)] uplc: bool, @@ -24,11 +28,18 @@ pub fn exec( Args { directory, deny, + watch, uplc, keep_traces, }: Args, ) -> miette::Result<()> { - with_project(directory.as_deref(), deny, |p| { - p.build(uplc, keep_traces.into()) - }) + 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| { + p.build(uplc, keep_traces.into()) + }) + } } diff --git a/crates/aiken/src/cmd/docs.rs b/crates/aiken/src/cmd/docs.rs index f03d2e7b..2bf0be39 100644 --- a/crates/aiken/src/cmd/docs.rs +++ b/crates/aiken/src/cmd/docs.rs @@ -1,4 +1,4 @@ -use aiken_project::watch::with_project; +use aiken_project::watch::{self, watch_project, with_project}; use std::path::PathBuf; #[derive(clap::Args)] @@ -11,6 +11,10 @@ pub struct Args { #[clap(short = 'D', long)] deny: bool, + /// When enabled, re-run the command on file changes instead of exiting + #[clap(short, long)] + watch: bool, + /// Output directory for the documentation #[clap(short = 'o', long)] destination: Option, @@ -20,8 +24,15 @@ pub fn exec( Args { directory, deny, + watch, destination, }: Args, ) -> miette::Result<()> { - with_project(directory.as_deref(), deny, |p| p.docs(destination.clone())) + 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())) + } }