Skip to content

Commit e139760

Browse files
committed
Refactor
1 parent cc101e7 commit e139760

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

src/elements/command/simple/run_internal.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,46 +43,43 @@ pub fn run_substitution_builtin(
4343
com: &mut SimpleCommand,
4444
core: &mut ShellCore,
4545
) -> Result<bool, ExecError> {
46-
if com.args.is_empty() {
47-
eprintln!("ShellCore::run_builtin");
48-
return Ok(false);
49-
}
50-
5146
if !core.subst_builtins.contains_key(&com.args[0]) {
5247
return Ok(false);
5348
}
5449

55-
let func = core.subst_builtins[&com.args[0]];
50+
let mut args = vec![com.args[0].clone()];
5651
let mut subs = vec![];
5752
for sub in com.substitutions_as_args.iter_mut() {
5853
match sub {
5954
SubsArgType::Subs(s) => subs.push((**s).clone()),
6055
SubsArgType::Other(w) => {
6156
for arg in w.eval(core)? {
6257
if arg.starts_with("-") || arg.starts_with("+") {
63-
com.args.push(arg);
64-
} else {
65-
let mut f = Feeder::new(&arg);
66-
match Substitution::parse(&mut f, core, true, false)? {
67-
Some(mut s) => {
68-
s.quoted = true;
69-
subs.push(s);
70-
}
71-
_ => {
72-
let mut s = Substitution::default();
73-
s.text = arg;
74-
s.left_hand.text = s.text.clone();
75-
s.left_hand.name = s.text.clone();
76-
s.quoted = true;
77-
subs.push(s);
78-
}
58+
args.push(arg);
59+
continue;
60+
}
61+
62+
let mut f = Feeder::new(&arg);
63+
match Substitution::parse(&mut f, core, true, false)? {
64+
Some(mut s) => {
65+
s.quoted = true;
66+
subs.push(s);
67+
}
68+
_ => {
69+
let mut s = Substitution::default();
70+
s.text = arg;
71+
s.left_hand.text = s.text.clone();
72+
s.left_hand.name = s.text.clone();
73+
s.quoted = true;
74+
subs.push(s);
7975
}
8076
}
8177
}
8278
}
8379
}
8480
}
8581

86-
core.db.exit_status = func(core, &com.args[..], &mut subs[..]);
82+
let func = core.subst_builtins[&com.args[0]];
83+
core.db.exit_status = func(core, &args[..], &mut subs[..]);
8784
Ok(true)
8885
}

0 commit comments

Comments
 (0)