Skip to content

Commit 9756ded

Browse files
committed
support initial run
1 parent f5c3ca6 commit 9756ded

File tree

1 file changed

+20
-17
lines changed
  • crates/bsnext_system/src/watch

1 file changed

+20
-17
lines changed

crates/bsnext_system/src/watch/mod.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub struct WatchCommand {
1111
#[arg(long = "command", short)]
1212
pub command: Vec<String>,
1313
/// Initial command to run before starting watchers
14-
#[arg(long = "initial", short)]
15-
pub initial: Vec<String>,
14+
#[arg(long = "initial", short, default_value = "false")]
15+
pub initial: bool,
1616
/// provide this flag to disable command prefixes
1717
#[arg(long = "no-prefix", default_value = "false")]
1818
pub no_prefix: bool,
@@ -37,24 +37,27 @@ impl From<WatchCommand> for MultiWatch {
3737
})
3838
.collect::<Vec<_>>();
3939

40-
let before = value
41-
.initial
42-
.iter()
43-
.map(ToOwned::to_owned)
44-
.enumerate()
45-
.map(move |(index, item)| {
46-
let name = Some(format!("initial:{}", index));
47-
let prefix = value.no_prefix.then_some(PrefixOpt::Bool(false));
48-
BeforeRunOptItem::Sh(ShRunOptItem {
49-
sh: item,
50-
name,
51-
prefix,
40+
let before = value.initial.then(|| {
41+
let cloned = run_opts.clone();
42+
cloned
43+
.into_iter()
44+
.map(|old| match old {
45+
RunOptItem::Sh(old) => {
46+
let name = Some("initial".to_string());
47+
let prefix = value.no_prefix.then_some(PrefixOpt::Bool(false));
48+
BeforeRunOptItem::Sh(ShRunOptItem {
49+
sh: old.sh,
50+
name,
51+
prefix,
52+
})
53+
}
54+
_ => unreachable!(),
5255
})
53-
})
54-
.collect::<Vec<_>>();
56+
.collect::<Vec<_>>()
57+
});
5558

5659
let spec = Spec {
57-
before: Some(before),
60+
before,
5861
run: Some(run_opts),
5962
..Default::default()
6063
};

0 commit comments

Comments
 (0)