Remove code duplication in glob (#13626)

This commit is contained in:
Stefan Holderbach 2024-08-14 23:11:00 +02:00 committed by GitHub
parent 803bc9c63f
commit 31b3104af7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -150,32 +150,7 @@ impl Command for Glob {
let glob_pattern =
match glob_pattern_input {
Value::String { val, .. } => {
if val.is_empty() {
return Err(ShellError::GenericError {
error: "glob pattern must not be empty".into(),
msg: "glob pattern is empty".into(),
span: Some(glob_span),
help: Some("add characters to the glob pattern".into()),
inner: vec![],
});
} else {
val
}
}
Value::Glob { val, .. } => {
if val.is_empty() {
return Err(ShellError::GenericError {
error: "glob pattern must not be empty".into(),
msg: "glob pattern is empty".into(),
span: Some(glob_span),
help: Some("add characters to the glob pattern".into()),
inner: vec![],
});
} else {
val
}
}
Value::String { val, .. } | Value::Glob { val, .. } => val,
_ => return Err(ShellError::IncorrectValue {
msg: "Incorrect glob pattern supplied to glob. Please use string or glob only."
.to_string(),
@ -184,6 +159,16 @@ impl Command for Glob {
}),
};
if glob_pattern.is_empty() {
return Err(ShellError::GenericError {
error: "glob pattern must not be empty".into(),
msg: "glob pattern is empty".into(),
span: Some(glob_span),
help: Some("add characters to the glob pattern".into()),
inner: vec![],
});
}
let folder_depth = if let Some(depth) = depth {
depth
} else {