Skip to content

Commit e01660d

Browse files
committed
created a function for user defined aliases
removed the command parameter and returned it in order to extend the command with an alias
1 parent ea83afd commit e01660d

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/bin/cargo/main.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,8 @@ fn list_commands(gctx: &GlobalContext) -> BTreeMap<String, CommandInfo> {
205205
}
206206

207207
// Add the user-defined aliases
208-
if let Ok(aliases) = gctx.get::<BTreeMap<String, StringOrVec>>("alias") {
209-
for (name, target) in aliases.iter() {
210-
commands.insert(
211-
name.to_string(),
212-
CommandInfo::Alias {
213-
target: target.clone(),
214-
},
215-
);
216-
}
217-
}
208+
let alias_commands = user_defined_aliases(gctx);
209+
commands.extend(alias_commands);
218210

219211
// `help` is special, so it needs to be inserted separately.
220212
commands.insert(
@@ -258,6 +250,21 @@ fn third_party_subcommands(gctx: &GlobalContext) -> BTreeMap<String, CommandInfo
258250
commands
259251
}
260252

253+
fn user_defined_aliases(gctx: &GlobalContext) -> BTreeMap<String, CommandInfo> {
254+
let mut commands = BTreeMap::new();
255+
if let Ok(aliases) = gctx.get::<BTreeMap<String, StringOrVec>>("alias") {
256+
for (name, target) in aliases.iter() {
257+
commands.insert(
258+
name.to_string(),
259+
CommandInfo::Alias {
260+
target: target.clone(),
261+
},
262+
);
263+
}
264+
}
265+
commands
266+
}
267+
261268
fn find_external_subcommand(gctx: &GlobalContext, cmd: &str) -> Option<PathBuf> {
262269
let command_exe = format!("cargo-{}{}", cmd, env::consts::EXE_SUFFIX);
263270
search_directories(gctx)

0 commit comments

Comments
 (0)