Match cleanup (#2248)

This commit is contained in:
Joseph T. Lyons
2020-07-25 08:40:35 -04:00
committed by GitHub
parent a77f0f7b41
commit de18b9ca2c
12 changed files with 40 additions and 123 deletions

View File

@ -581,17 +581,11 @@ pub fn set_rustyline_configuration() -> (Editor<Helper>, IndexMap<String, Value>
// }
// _ => rustyline::config::HistoryDuplicates::AlwaysAdd,
// };
let history_duplicates = match value.as_bool() {
Ok(b) => b,
_ => true,
};
let history_duplicates = value.as_bool().unwrap_or(true);
rl.set_history_ignore_dups(history_duplicates);
}
"history_ignore_space" => {
let history_ignore_space = match value.as_bool() {
Ok(b) => b,
_ => true,
};
let history_ignore_space = value.as_bool().unwrap_or(true);
rl.set_history_ignore_space(history_ignore_space);
}
"completion_type" => {
@ -635,10 +629,7 @@ pub fn set_rustyline_configuration() -> (Editor<Helper>, IndexMap<String, Value>
rl.set_edit_mode(edit_mode);
}
"auto_add_history" => {
let auto_add_history = match value.as_bool() {
Ok(b) => b,
_ => true,
};
let auto_add_history = value.as_bool().unwrap_or(true);
rl.set_auto_add_history(auto_add_history);
}
"bell_style" => {
@ -720,13 +711,10 @@ pub async fn cli(
let _ = load_plugins(&mut context);
let (mut rl, config) = set_rustyline_configuration();
let use_starship = match config.get("use_starship") {
Some(b) => match b.as_bool() {
Ok(b) => b,
_ => false,
},
_ => false,
};
let use_starship = config
.get("use_starship")
.map(|x| x.is_true())
.unwrap_or(false);
#[cfg(windows)]
{

View File

@ -100,7 +100,7 @@ pub async fn cal(
(current_month, current_month)
};
let add_months_of_year_to_table_result = add_months_of_year_to_table(
add_months_of_year_to_table(
&args,
&mut calendar_vec_deque,
&tag,
@ -108,12 +108,9 @@ pub async fn cal(
month_range,
current_month,
current_day_option,
);
)?;
match add_months_of_year_to_table_result {
Ok(()) => Ok(futures::stream::iter(calendar_vec_deque).to_output_stream()),
Err(error) => Err(error),
}
Ok(futures::stream::iter(calendar_vec_deque).to_output_stream())
}
fn get_invalid_year_shell_error(year_tag: &Tag) -> ShellError {

View File

@ -60,13 +60,13 @@ async fn default(
Ok(input
.map(move |item| {
let should_add = match item {
let should_add = matches!(
item,
Value {
value: UntaggedValue::Row(ref r),
..
} => r.get_data(&column.item).borrow().is_none(),
_ => false,
};
} if r.get_data(&column.item).borrow().is_none()
);
if should_add {
match item.insert_data_at_path(&column.item, value.clone()) {

View File

@ -140,10 +140,7 @@ impl WholeStreamCommand for RunExternalCommand {
external::run_external_command(command, &mut external_context, input, &scope, is_last)
.await;
match result {
Ok(stream) => Ok(stream.to_output_stream()),
Err(e) => Err(e),
}
Ok(result?.to_output_stream())
}
}

View File

@ -251,10 +251,7 @@ async fn save(
};
};
match content {
Ok(save_data) => shell_manager.save(&full_path, &save_data, name.span),
Err(e) => Err(e),
}
shell_manager.save(&full_path, &content?, name.span)
}
fn string_from(input: &[Value]) -> String {

View File

@ -91,10 +91,7 @@ pub fn split(
crate::utils::data::split(&values, &Some(block), &name)
}
Grouper::ByColumn(None) => {
let block = Box::new(move |_, row: &Value| match as_string(row) {
Ok(group_key) => Ok(group_key),
Err(reason) => Err(reason),
});
let block = Box::new(move |_, row: &Value| as_string(row));
crate::utils::data::split(&values, &Some(block), &name)
}

View File

@ -74,13 +74,10 @@ pub fn from_list(values: &[Value], starting_idx: usize) -> nu_table::Table {
_ => ansi_term::Color::Green,
};
let header_bold = match config.get("header_bold") {
Some(b) => match b.as_bool() {
Ok(b) => b,
_ => true,
},
_ => true,
};
let header_bold = config
.get("header_bold")
.map(|x| x.as_bool().unwrap_or(true))
.unwrap_or(true);
TextStyle {
alignment: header_align,

View File

@ -2,13 +2,10 @@ use crate::prelude::*;
pub fn current_branch() -> Option<String> {
if let Ok(config) = crate::data::config::config(Tag::unknown()) {
let use_starship = match config.get("use_starship") {
Some(b) => match b.as_bool() {
Ok(b) => b,
_ => false,
},
_ => false,
};
let use_starship = config
.get("use_starship")
.map(|x| x.is_true())
.unwrap_or(false);
if !use_starship {
#[cfg(feature = "git2")]

View File

@ -292,10 +292,7 @@ impl Shell for FilesystemShell {
));
}
let any_source_is_dir = sources.iter().any(|f| match f {
Ok(f) => f.is_dir(),
Err(_) => false,
});
let any_source_is_dir = sources.iter().any(|f| matches!(f, Ok(f) if f.is_dir()));
if any_source_is_dir && !recursive.item {
return Err(ShellError::labeled_error(