mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 00:13:21 +01:00
Remove code duplication in glob (#13626)
This commit is contained in:
parent
803bc9c63f
commit
31b3104af7
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user