mirror of
https://github.com/nushell/nushell.git
synced 2025-05-01 00:24:29 +02: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 =
|
let glob_pattern =
|
||||||
match glob_pattern_input {
|
match glob_pattern_input {
|
||||||
Value::String { val, .. } => {
|
Value::String { val, .. } | Value::Glob { val, .. } => 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => return Err(ShellError::IncorrectValue {
|
_ => return Err(ShellError::IncorrectValue {
|
||||||
msg: "Incorrect glob pattern supplied to glob. Please use string or glob only."
|
msg: "Incorrect glob pattern supplied to glob. Please use string or glob only."
|
||||||
.to_string(),
|
.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 {
|
let folder_depth = if let Some(depth) = depth {
|
||||||
depth
|
depth
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user