Skip to content

Commit d341a66

Browse files
committed
fixed #115: allow base group if cond groups exists with add and rm
1 parent 7005d74 commit d341a66

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

src/symlinks.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,30 @@ impl<'a> SymlinkHandler<'a> {
528528
}
529529
}
530530

531+
fn get_nonexistent_groups_with_no_related_groups(
532+
sym: &SymlinkHandler,
533+
groups: &[String],
534+
) -> Option<Vec<String>> {
535+
let mut nonexistent_groups = Vec::new();
536+
for group in groups {
537+
if sym
538+
.get_related_conditional_groups(
539+
group,
540+
SymlinkType::Symlinked | SymlinkType::NotSymlinked | SymlinkType::NotOwned,
541+
false,
542+
)
543+
.is_none()
544+
{
545+
nonexistent_groups.push(group.clone());
546+
}
547+
}
548+
549+
if nonexistent_groups.is_empty() {
550+
return None;
551+
}
552+
553+
Some(nonexistent_groups)
554+
}
531555
/// Adds symlinks
532556
#[allow(clippy::too_many_arguments)]
533557
pub fn add_cmd(
@@ -553,9 +577,7 @@ pub fn add_cmd(
553577

554578
let mut sym = SymlinkHandler::try_new(ctx)?;
555579

556-
if let Some(nonexistent_groups) =
557-
dotfiles::get_nonexistent_groups(ctx.profile.clone(), DotfileType::Configs, groups)
558-
{
580+
if let Some(nonexistent_groups) = get_nonexistent_groups_with_no_related_groups(&sym, groups) {
559581
for group in nonexistent_groups {
560582
eprintln!("{}", t!("errors.x_doesnt_exist", x = group).red());
561583
}
@@ -709,9 +731,7 @@ pub fn remove_cmd(ctx: &Context, groups: &[String], exclude: &[String]) -> Resul
709731
return Ok(());
710732
}
711733

712-
if let Some(nonexistent_groups) =
713-
dotfiles::get_nonexistent_groups(ctx.profile.clone(), DotfileType::Configs, groups)
714-
{
734+
if let Some(nonexistent_groups) = get_nonexistent_groups_with_no_related_groups(&sym, groups) {
715735
for group in nonexistent_groups {
716736
eprintln!("{}", t!("errors.x_doesnt_exist", x = group).red());
717737
}

0 commit comments

Comments
 (0)