Skip to content

Commit a2a2cf0

Browse files
committed
Add fallback search sections to cargo remove
Signed-off-by: hi-rustin <[email protected]>
1 parent d2f6a04 commit a2a2cf0

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/bin/cargo/commands/remove.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,14 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
9696
.cloned()
9797
.collect::<Vec<_>>();
9898

99-
let section = parse_section(args);
99+
let (section, fallback_search_sections) = parse_section(args);
100100

101101
let options = RemoveOptions {
102102
config,
103103
spec,
104104
dependencies,
105105
section,
106+
fallback_search_sections,
106107
dry_run,
107108
};
108109
remove(&options)?;
@@ -134,26 +135,38 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
134135
Ok(())
135136
}
136137

137-
fn parse_section(args: &ArgMatches) -> DepTable {
138+
fn parse_section(args: &ArgMatches) -> (DepTable, Vec<DepTable>) {
138139
let dev = args.flag("dev");
139140
let build = args.flag("build");
140141

142+
let mut search_kinds = Vec::new();
143+
141144
let kind = if dev {
145+
search_kinds.extend_from_slice(&[DepKind::Build, DepKind::Normal]);
142146
DepKind::Development
143147
} else if build {
148+
search_kinds.extend_from_slice(&[DepKind::Development, DepKind::Normal]);
144149
DepKind::Build
145150
} else {
151+
search_kinds.extend_from_slice(&[DepKind::Build, DepKind::Development]);
146152
DepKind::Normal
147153
};
148154

149155
let mut table = DepTable::new().set_kind(kind);
150-
156+
let mut search_tables = search_kinds
157+
.iter()
158+
.map(|k| DepTable::new().set_kind(*k))
159+
.collect::<Vec<_>>();
151160
if let Some(target) = args.get_one::<String>("target") {
152161
assert!(!target.is_empty(), "Target specification may not be empty");
153162
table = table.set_target(target);
163+
search_tables = search_tables
164+
.into_iter()
165+
.map(|t| t.set_target(target.clone()))
166+
.collect::<Vec<_>>();
154167
}
155168

156-
table
169+
(table, search_tables)
157170
}
158171

159172
/// Clean up the workspace.dependencies, profile, patch, and replace sections of the root manifest

src/cargo/ops/cargo_remove.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub struct RemoveOptions<'a> {
1717
pub dependencies: Vec<String>,
1818
/// Which dependency section to remove these from
1919
pub section: DepTable,
20+
/// Try to search for the dependency in these sections if it is not found in the specified section
21+
pub fallback_search_sections: Vec<DepTable>,
2022
/// Whether or not to actually write the manifest
2123
pub dry_run: bool,
2224
}

0 commit comments

Comments
 (0)