Skip to content

Commit ea83afd

Browse files
committed
took the functionality of the third party subcommand from the list_commands function
corrected the formatting
1 parent 5408cc2 commit ea83afd

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

src/bin/cargo/main.rs

+32-27
Original file line numberDiff line numberDiff line change
@@ -182,33 +182,7 @@ fn aliased_command(gctx: &GlobalContext, command: &str) -> CargoResult<Option<Ve
182182

183183
/// List all runnable commands
184184
fn list_commands(gctx: &GlobalContext) -> BTreeMap<String, CommandInfo> {
185-
let prefix = "cargo-";
186-
let suffix = env::consts::EXE_SUFFIX;
187-
let mut commands = BTreeMap::new();
188-
for dir in search_directories(gctx) {
189-
let entries = match fs::read_dir(dir) {
190-
Ok(entries) => entries,
191-
_ => continue,
192-
};
193-
for entry in entries.filter_map(|e| e.ok()) {
194-
let path = entry.path();
195-
let Some(filename) = path.file_name().and_then(|s| s.to_str()) else {
196-
continue;
197-
};
198-
let Some(name) = filename
199-
.strip_prefix(prefix)
200-
.and_then(|s| s.strip_suffix(suffix))
201-
else {
202-
continue;
203-
};
204-
if is_executable(entry.path()) {
205-
commands.insert(
206-
name.to_string(),
207-
CommandInfo::External { path: path.clone() },
208-
);
209-
}
210-
}
211-
}
185+
let mut commands = third_party_subcommands(gctx);
212186

213187
for cmd in commands::builtin() {
214188
commands.insert(
@@ -253,6 +227,37 @@ fn list_commands(gctx: &GlobalContext) -> BTreeMap<String, CommandInfo> {
253227
commands
254228
}
255229

230+
fn third_party_subcommands(gctx: &GlobalContext) -> BTreeMap<String, CommandInfo> {
231+
let prefix = "cargo-";
232+
let suffix = env::consts::EXE_SUFFIX;
233+
let mut commands = BTreeMap::new();
234+
for dir in search_directories(gctx) {
235+
let entries = match fs::read_dir(dir) {
236+
Ok(entries) => entries,
237+
_ => continue,
238+
};
239+
for entry in entries.filter_map(|e| e.ok()) {
240+
let path = entry.path();
241+
let Some(filename) = path.file_name().and_then(|s| s.to_str()) else {
242+
continue;
243+
};
244+
let Some(name) = filename
245+
.strip_prefix(prefix)
246+
.and_then(|s| s.strip_suffix(suffix))
247+
else {
248+
continue;
249+
};
250+
if is_executable(entry.path()) {
251+
commands.insert(
252+
name.to_string(),
253+
CommandInfo::External { path: path.clone() },
254+
);
255+
}
256+
}
257+
}
258+
commands
259+
}
260+
256261
fn find_external_subcommand(gctx: &GlobalContext, cmd: &str) -> Option<PathBuf> {
257262
let command_exe = format!("cargo-{}{}", cmd, env::consts::EXE_SUFFIX);
258263
search_directories(gctx)

0 commit comments

Comments
 (0)