INNER CODE UNIT · Rust
alias_expand_line
databricks/click · src/command_processor.rs:90
pub fn alias_expand_line(env: &Env, line: &str) -> String {
let expa = env.try_expand_alias(line, None);
let mut alias_stack = vec![expa];
#[allow(clippy::while_let_loop)] // needed due to borrow restrictions
loop {
let expa = match alias_stack.last().unwrap().expansion {
Some(prev) => {
// previous thing expanded an alias, so try and expand that too
env.try_expand_alias(prev.expanded.as_str(), Some(prev.alias.as_str()))
}
None => break,
};
alias_stack.push(expa);
}
// At this point, all the "real" stuff is in the chain of "rest" memebers of the
// alias_stack, let's gather them up
let rests: Vec<&str> = alias_stack.iter().rev().map(|ea| ea.rest).collect();
rests.concat()