forked from extern/nushell
Match cleanup (#2184)
* Use `unwrap_or()` to remove `match` * Use `?` for error propogation, and remove `match`
This commit is contained in:
parent
c299d207f7
commit
7c0a830d84
@ -149,10 +149,7 @@ pub fn load_plugins(context: &mut Context) -> Result<(), ShellError> {
|
||||
.map(|path| {
|
||||
let bin_name = {
|
||||
if let Some(name) = path.file_name() {
|
||||
match name.to_str() {
|
||||
Some(raw) => raw,
|
||||
None => "",
|
||||
}
|
||||
name.to_str().unwrap_or("")
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
@ -62,10 +62,7 @@ async fn operate(
|
||||
Ok(input
|
||||
.map(move |v| {
|
||||
if column_paths.is_empty() {
|
||||
match action(&v, v.tag()) {
|
||||
Ok(out) => ReturnSuccess::value(out),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
ReturnSuccess::value(action(&v, v.tag())?)
|
||||
} else {
|
||||
let mut ret = v;
|
||||
|
||||
|
@ -62,10 +62,7 @@ async fn operate(
|
||||
Ok(input
|
||||
.map(move |v| {
|
||||
if column_paths.is_empty() {
|
||||
match action(&v, v.tag()) {
|
||||
Ok(out) => ReturnSuccess::value(out),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
ReturnSuccess::value(action(&v, v.tag())?)
|
||||
} else {
|
||||
let mut ret = v;
|
||||
|
||||
|
@ -80,10 +80,7 @@ async fn operate(
|
||||
Ok(input
|
||||
.map(move |v| {
|
||||
if column_paths.is_empty() {
|
||||
match action(&v, &options, v.tag()) {
|
||||
Ok(out) => ReturnSuccess::value(out),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
ReturnSuccess::value(action(&v, &options, v.tag())?)
|
||||
} else {
|
||||
let mut ret = v;
|
||||
|
||||
|
@ -96,10 +96,7 @@ async fn operate(
|
||||
Ok(input
|
||||
.map(move |v| {
|
||||
if column_paths.is_empty() {
|
||||
match action(&v, v.tag(), digits, group_digits) {
|
||||
Ok(out) => ReturnSuccess::value(out),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
ReturnSuccess::value(action(&v, v.tag(), digits, group_digits)?)
|
||||
} else {
|
||||
let mut ret = v;
|
||||
for path in &column_paths {
|
||||
|
@ -73,10 +73,7 @@ async fn operate(
|
||||
Ok(input
|
||||
.map(move |v| {
|
||||
if column_paths.is_empty() {
|
||||
match action(&v, &options, v.tag()) {
|
||||
Ok(out) => ReturnSuccess::value(out),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
ReturnSuccess::value(action(&v, &options, v.tag())?)
|
||||
} else {
|
||||
let mut ret = v;
|
||||
|
||||
|
@ -108,10 +108,7 @@ async fn operate(
|
||||
Ok(input
|
||||
.map(move |v| {
|
||||
if column_paths.is_empty() {
|
||||
match action(&v, &options, v.tag()) {
|
||||
Ok(out) => ReturnSuccess::value(out),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
ReturnSuccess::value(action(&v, &options, v.tag())?)
|
||||
} else {
|
||||
let mut ret = v;
|
||||
|
||||
|
@ -81,10 +81,7 @@ async fn operate(
|
||||
Ok(input
|
||||
.map(move |v| {
|
||||
if column_paths.is_empty() {
|
||||
match action(&v, &options, v.tag()) {
|
||||
Ok(out) => ReturnSuccess::value(out),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
ReturnSuccess::value(action(&v, &options, v.tag())?)
|
||||
} else {
|
||||
let mut ret = v;
|
||||
|
||||
|
@ -65,10 +65,7 @@ async fn operate(
|
||||
Ok(input
|
||||
.map(move |v| {
|
||||
if column_paths.is_empty() {
|
||||
match action(&v, v.tag()) {
|
||||
Ok(out) => ReturnSuccess::value(out),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
ReturnSuccess::value(action(&v, v.tag())?)
|
||||
} else {
|
||||
let mut ret = v;
|
||||
|
||||
|
@ -65,10 +65,7 @@ async fn operate(
|
||||
Ok(input
|
||||
.map(move |v| {
|
||||
if column_paths.is_empty() {
|
||||
match action(&v, v.tag()) {
|
||||
Ok(out) => ReturnSuccess::value(out),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
ReturnSuccess::value(action(&v, v.tag())?)
|
||||
} else {
|
||||
let mut ret = v;
|
||||
|
||||
|
@ -79,10 +79,7 @@ async fn operate(
|
||||
Ok(input
|
||||
.map(move |v| {
|
||||
if column_paths.is_empty() {
|
||||
match action(&v, v.tag(), to_trim) {
|
||||
Ok(out) => ReturnSuccess::value(out),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
ReturnSuccess::value(action(&v, v.tag(), to_trim)?)
|
||||
} else {
|
||||
let mut ret = v;
|
||||
|
||||
|
@ -62,10 +62,7 @@ async fn operate(
|
||||
Ok(input
|
||||
.map(move |v| {
|
||||
if column_paths.is_empty() {
|
||||
match action(&v, v.tag()) {
|
||||
Ok(out) => ReturnSuccess::value(out),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
ReturnSuccess::value(action(&v, v.tag())?)
|
||||
} else {
|
||||
let mut ret = v;
|
||||
|
||||
|
@ -37,10 +37,7 @@ impl ValueStructure {
|
||||
}
|
||||
|
||||
let path = if path.starts_with("/") {
|
||||
match path.strip_prefix("/") {
|
||||
Ok(p) => p,
|
||||
Err(_) => path,
|
||||
}
|
||||
path.strip_prefix("/").unwrap_or(path)
|
||||
} else {
|
||||
path
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user