Skip to content

Commit f49037f

Browse files
committed
refactor: use PathBuf for folder arg
1 parent 271a112 commit f49037f

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

rewatch/src/cli.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use std::{ffi::OsString, ops::Deref};
1+
use std::{
2+
ffi::OsString,
3+
ops::Deref,
4+
path::{Path, PathBuf},
5+
};
26

37
use clap::{Args, Parser, Subcommand};
48
use clap_verbosity_flag::InfoLevel;
@@ -45,7 +49,7 @@ pub struct Cli {
4549
pub struct FolderArg {
4650
/// The relative path to where the main rescript.json resides. IE - the root of your project.
4751
#[arg(default_value = ".")]
48-
pub folder: String,
52+
pub folder: PathBuf,
4953
}
5054

5155
#[derive(Args, Debug, Clone)]
@@ -219,7 +223,7 @@ pub enum Command {
219223
}
220224

221225
impl Deref for FolderArg {
222-
type Target = str;
226+
type Target = Path;
223227

224228
fn deref(&self) -> &Self::Target {
225229
&self.folder

rewatch/src/lock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ fn create(lockfile_location: &Path, pid: u32) -> Lock {
5959
.unwrap_or_else(|e| Lock::Error(Error::WritingLockfile(e)))
6060
}
6161

62-
pub fn get(folder: &str) -> Lock {
63-
let ___location = Path::new(folder).join("lib").join(LOCKFILE);
62+
pub fn get(folder: &Path) -> Lock {
63+
let ___location = folder.join("lib").join(LOCKFILE);
6464
let pid = process::id();
6565

6666
match fs::read_to_string(&___location) {

rewatch/src/main.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn main() -> Result<()> {
3939

4040
match build::build(
4141
&build_args.filter,
42-
Path::new(&build_args.folder as &str),
42+
&build_args.folder,
4343
show_progress,
4444
build_args.no_timing,
4545
*build_args.create_sourcedirs,
@@ -80,12 +80,7 @@ fn main() -> Result<()> {
8080
} => {
8181
let _lock = get_lock(&folder);
8282

83-
build::clean::clean(
84-
Path::new(&folder as &str),
85-
show_progress,
86-
*snapshot_output,
87-
dev.dev,
88-
)
83+
build::clean::clean(&folder, show_progress, *snapshot_output, dev.dev)
8984
}
9085
cli::Command::Legacy { legacy_args } => {
9186
let code = build::pass_through_legacy(legacy_args);
@@ -100,7 +95,7 @@ fn main() -> Result<()> {
10095
}
10196
}
10297

103-
fn get_lock(folder: &str) -> lock::Lock {
98+
fn get_lock(folder: &Path) -> lock::Lock {
10499
match lock::get(folder) {
105100
lock::Lock::Error(error) => {
106101
println!("Could not start ReScript build: {error}");

rewatch/src/watcher.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ async fn async_watch(
311311
pub fn start(
312312
filter: &Option<regex::Regex>,
313313
show_progress: bool,
314-
folder: &str,
314+
folder: &Path,
315315
after_build: Option<String>,
316316
create_sourcedirs: bool,
317317
build_dev_deps: bool,
@@ -325,17 +325,15 @@ pub fn start(
325325
let mut watcher = RecommendedWatcher::new(move |res| producer.push(res), Config::default())
326326
.expect("Could not create watcher");
327327

328-
log::debug!("watching {folder}");
328+
log::debug!("watching {}", folder.display());
329329

330330
watcher
331331
.watch(folder.as_ref(), RecursiveMode::Recursive)
332332
.expect("Could not start watcher");
333333

334-
let path = Path::new(folder);
335-
336334
if let Err(e) = async_watch(AsyncWatchArgs {
337335
q: consumer,
338-
path,
336+
path: folder,
339337
show_progress,
340338
filter,
341339
after_build,

0 commit comments

Comments
 (0)