Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions rewatch/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ use std::{ffi::OsString, ops::Deref};

use clap::{Args, Parser, Subcommand};
use clap_verbosity_flag::InfoLevel;
use regex::Regex;

fn parse_regex(s: &str) -> Result<Regex, regex::Error> {
Regex::new(s)
}

/// ReScript - Fast, Simple, Fully Typed JavaScript from the Future
#[derive(Parser, Debug)]
Expand Down Expand Up @@ -39,8 +44,8 @@ pub struct FilterArg {
///
/// Filter allows for a regex to be supplied which will filter the files to be compiled. For
/// instance, to filter out test files for compilation while doing feature work.
#[arg(short, long)]
pub filter: Option<String>,
#[arg(short, long, value_parser = parse_regex)]
pub filter: Option<Regex>,
}

#[derive(Args, Debug, Clone)]
Expand Down Expand Up @@ -187,7 +192,7 @@ impl Deref for FolderArg {
}

impl Deref for FilterArg {
type Target = Option<String>;
type Target = Option<Regex>;

fn deref(&self) -> &Self::Target {
&self.filter
Expand Down
14 changes: 2 additions & 12 deletions rewatch/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::Result;
use clap::Parser;
use log::LevelFilter;
use regex::Regex;
use std::{io::Write, path::Path};

use rewatch::{build, cli, cmd, lock, watcher};
Expand Down Expand Up @@ -31,13 +30,8 @@ fn main() -> Result<()> {
cli::Command::Build(build_args) => {
let _lock = get_lock(&build_args.folder);

let filter = build_args
.filter
.as_ref()
.map(|filter| Regex::new(&filter).expect("Could not parse regex"));

match build::build(
&filter,
&build_args.filter,
Path::new(&build_args.folder as &str),
show_progress,
build_args.no_timing,
Expand All @@ -60,12 +54,8 @@ fn main() -> Result<()> {
cli::Command::Watch(watch_args) => {
let _lock = get_lock(&watch_args.folder);

let filter = watch_args
.filter
.as_ref()
.map(|filter| Regex::new(&filter).expect("Could not parse regex"));
watcher::start(
&filter,
&watch_args.filter,
show_progress,
&watch_args.folder,
(*watch_args.after_build).clone(),
Expand Down