mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
took the functionality of the third party subcommand from the list_commands function
corrected the formatting
This commit is contained in:
parent
5408cc22ac
commit
ea83afd783
@ -182,33 +182,7 @@ fn aliased_command(gctx: &GlobalContext, command: &str) -> CargoResult<Option<Ve
|
|||||||
|
|
||||||
/// List all runnable commands
|
/// List all runnable commands
|
||||||
fn list_commands(gctx: &GlobalContext) -> BTreeMap<String, CommandInfo> {
|
fn list_commands(gctx: &GlobalContext) -> BTreeMap<String, CommandInfo> {
|
||||||
let prefix = "cargo-";
|
let mut commands = third_party_subcommands(gctx);
|
||||||
let suffix = env::consts::EXE_SUFFIX;
|
|
||||||
let mut commands = BTreeMap::new();
|
|
||||||
for dir in search_directories(gctx) {
|
|
||||||
let entries = match fs::read_dir(dir) {
|
|
||||||
Ok(entries) => entries,
|
|
||||||
_ => continue,
|
|
||||||
};
|
|
||||||
for entry in entries.filter_map(|e| e.ok()) {
|
|
||||||
let path = entry.path();
|
|
||||||
let Some(filename) = path.file_name().and_then(|s| s.to_str()) else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
let Some(name) = filename
|
|
||||||
.strip_prefix(prefix)
|
|
||||||
.and_then(|s| s.strip_suffix(suffix))
|
|
||||||
else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
if is_executable(entry.path()) {
|
|
||||||
commands.insert(
|
|
||||||
name.to_string(),
|
|
||||||
CommandInfo::External { path: path.clone() },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for cmd in commands::builtin() {
|
for cmd in commands::builtin() {
|
||||||
commands.insert(
|
commands.insert(
|
||||||
@ -253,6 +227,37 @@ fn list_commands(gctx: &GlobalContext) -> BTreeMap<String, CommandInfo> {
|
|||||||
commands
|
commands
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn third_party_subcommands(gctx: &GlobalContext) -> BTreeMap<String, CommandInfo> {
|
||||||
|
let prefix = "cargo-";
|
||||||
|
let suffix = env::consts::EXE_SUFFIX;
|
||||||
|
let mut commands = BTreeMap::new();
|
||||||
|
for dir in search_directories(gctx) {
|
||||||
|
let entries = match fs::read_dir(dir) {
|
||||||
|
Ok(entries) => entries,
|
||||||
|
_ => continue,
|
||||||
|
};
|
||||||
|
for entry in entries.filter_map(|e| e.ok()) {
|
||||||
|
let path = entry.path();
|
||||||
|
let Some(filename) = path.file_name().and_then(|s| s.to_str()) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let Some(name) = filename
|
||||||
|
.strip_prefix(prefix)
|
||||||
|
.and_then(|s| s.strip_suffix(suffix))
|
||||||
|
else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
if is_executable(entry.path()) {
|
||||||
|
commands.insert(
|
||||||
|
name.to_string(),
|
||||||
|
CommandInfo::External { path: path.clone() },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
commands
|
||||||
|
}
|
||||||
|
|
||||||
fn find_external_subcommand(gctx: &GlobalContext, cmd: &str) -> Option<PathBuf> {
|
fn find_external_subcommand(gctx: &GlobalContext, cmd: &str) -> Option<PathBuf> {
|
||||||
let command_exe = format!("cargo-{}{}", cmd, env::consts::EXE_SUFFIX);
|
let command_exe = format!("cargo-{}{}", cmd, env::consts::EXE_SUFFIX);
|
||||||
search_directories(gctx)
|
search_directories(gctx)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user