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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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(

View File

@ -69,10 +69,7 @@ impl EvaluatedArgs {
/// Return true if the set of named arguments contains the name provided
pub fn has(&self, name: &str) -> bool {
match &self.named {
None => false,
Some(named) => named.contains_key(name),
}
matches!(&self.named, Some(named) if named.contains_key(name))
}
/// Gets the corresponding Value for the named argument given, if possible

View File

@ -64,10 +64,7 @@ impl Ord for Dictionary {
impl PartialEq<Value> for Dictionary {
/// Test a dictionary against a Value for equality
fn eq(&self, other: &Value) -> bool {
match &other.value {
UntaggedValue::Row(d) => self == d,
_ => false,
}
matches!(&other.value, UntaggedValue::Row(d) if self == d)
}
}

View File

@ -48,48 +48,15 @@ pub fn view_text_value(value: &Value) {
_ => 4u64,
}
}
"colored_output" => {
colored_output = match value.as_bool() {
Ok(b) => b,
_ => true,
}
}
"true_color" => {
true_color = match value.as_bool() {
Ok(b) => b,
_ => true,
}
}
"header" => {
header = match value.as_bool() {
Ok(b) => b,
_ => true,
}
}
"line_numbers" => {
line_numbers = match value.as_bool() {
Ok(b) => b,
_ => true,
}
}
"grid" => {
grid = match value.as_bool() {
Ok(b) => b,
_ => true,
}
}
"colored_output" => colored_output = value.as_bool().unwrap_or(true),
"true_color" => true_color = value.as_bool().unwrap_or(true),
"header" => header = value.as_bool().unwrap_or(true),
"line_numbers" => line_numbers = value.as_bool().unwrap_or(true),
"grid" => grid = value.as_bool().unwrap_or(true),
"vcs_modification_markers" => {
vcs_modification_markers = match value.as_bool() {
Ok(b) => b,
_ => true,
}
}
"snip" => {
snip = match value.as_bool() {
Ok(b) => b,
_ => true,
}
vcs_modification_markers = value.as_bool().unwrap_or(true)
}
"snip" => snip = value.as_bool().unwrap_or(true),
"wrapping_mode" => {
wrapping_mode = match value.as_string() {
Ok(s) if s.to_lowercase() == "nowrapping" => {
@ -101,12 +68,7 @@ pub fn view_text_value(value: &Value) {
_ => bat::WrappingMode::NoWrapping,
}
}
"use_italics" => {
use_italics = match value.as_bool() {
Ok(b) => b,
_ => true,
}
}
"use_italics" => use_italics = value.as_bool().unwrap_or(true),
"paging_mode" => {
paging_mode = match value.as_string() {
Ok(s) if s.to_lowercase() == "always" => bat::PagingMode::Always,
@ -117,19 +79,13 @@ pub fn view_text_value(value: &Value) {
_ => bat::PagingMode::QuitIfOneScreen,
}
}
"pager" => {
pager = match value.as_string() {
Ok(s) => s,
_ => "less".to_string(),
}
}
"pager" => pager = value.as_string().unwrap_or_else(|_| "less".to_string()),
"line_ranges" => line_ranges = bat::line_range::LineRanges::all(), // not real sure what to do with this
"highlight_range" => _highlight_range = "0,0", //ignore config value for now
"theme" => {
theme = match value.as_string() {
Ok(s) => s,
_ => "OneDarkHalf".to_string(),
}
theme = value
.as_string()
.unwrap_or_else(|_| "OneDarkHalf".to_string())
}
_ => (),
}