forked from extern/nushell
Match cleanup (#2248)
This commit is contained in:
parent
a77f0f7b41
commit
de18b9ca2c
@ -581,17 +581,11 @@ pub fn set_rustyline_configuration() -> (Editor<Helper>, IndexMap<String, Value>
|
|||||||
// }
|
// }
|
||||||
// _ => rustyline::config::HistoryDuplicates::AlwaysAdd,
|
// _ => rustyline::config::HistoryDuplicates::AlwaysAdd,
|
||||||
// };
|
// };
|
||||||
let history_duplicates = match value.as_bool() {
|
let history_duplicates = value.as_bool().unwrap_or(true);
|
||||||
Ok(b) => b,
|
|
||||||
_ => true,
|
|
||||||
};
|
|
||||||
rl.set_history_ignore_dups(history_duplicates);
|
rl.set_history_ignore_dups(history_duplicates);
|
||||||
}
|
}
|
||||||
"history_ignore_space" => {
|
"history_ignore_space" => {
|
||||||
let history_ignore_space = match value.as_bool() {
|
let history_ignore_space = value.as_bool().unwrap_or(true);
|
||||||
Ok(b) => b,
|
|
||||||
_ => true,
|
|
||||||
};
|
|
||||||
rl.set_history_ignore_space(history_ignore_space);
|
rl.set_history_ignore_space(history_ignore_space);
|
||||||
}
|
}
|
||||||
"completion_type" => {
|
"completion_type" => {
|
||||||
@ -635,10 +629,7 @@ pub fn set_rustyline_configuration() -> (Editor<Helper>, IndexMap<String, Value>
|
|||||||
rl.set_edit_mode(edit_mode);
|
rl.set_edit_mode(edit_mode);
|
||||||
}
|
}
|
||||||
"auto_add_history" => {
|
"auto_add_history" => {
|
||||||
let auto_add_history = match value.as_bool() {
|
let auto_add_history = value.as_bool().unwrap_or(true);
|
||||||
Ok(b) => b,
|
|
||||||
_ => true,
|
|
||||||
};
|
|
||||||
rl.set_auto_add_history(auto_add_history);
|
rl.set_auto_add_history(auto_add_history);
|
||||||
}
|
}
|
||||||
"bell_style" => {
|
"bell_style" => {
|
||||||
@ -720,13 +711,10 @@ pub async fn cli(
|
|||||||
let _ = load_plugins(&mut context);
|
let _ = load_plugins(&mut context);
|
||||||
|
|
||||||
let (mut rl, config) = set_rustyline_configuration();
|
let (mut rl, config) = set_rustyline_configuration();
|
||||||
let use_starship = match config.get("use_starship") {
|
let use_starship = config
|
||||||
Some(b) => match b.as_bool() {
|
.get("use_starship")
|
||||||
Ok(b) => b,
|
.map(|x| x.is_true())
|
||||||
_ => false,
|
.unwrap_or(false);
|
||||||
},
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
|
@ -100,7 +100,7 @@ pub async fn cal(
|
|||||||
(current_month, current_month)
|
(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,
|
&args,
|
||||||
&mut calendar_vec_deque,
|
&mut calendar_vec_deque,
|
||||||
&tag,
|
&tag,
|
||||||
@ -108,12 +108,9 @@ pub async fn cal(
|
|||||||
month_range,
|
month_range,
|
||||||
current_month,
|
current_month,
|
||||||
current_day_option,
|
current_day_option,
|
||||||
);
|
)?;
|
||||||
|
|
||||||
match add_months_of_year_to_table_result {
|
Ok(futures::stream::iter(calendar_vec_deque).to_output_stream())
|
||||||
Ok(()) => Ok(futures::stream::iter(calendar_vec_deque).to_output_stream()),
|
|
||||||
Err(error) => Err(error),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_invalid_year_shell_error(year_tag: &Tag) -> ShellError {
|
fn get_invalid_year_shell_error(year_tag: &Tag) -> ShellError {
|
||||||
|
@ -60,13 +60,13 @@ async fn default(
|
|||||||
|
|
||||||
Ok(input
|
Ok(input
|
||||||
.map(move |item| {
|
.map(move |item| {
|
||||||
let should_add = match item {
|
let should_add = matches!(
|
||||||
|
item,
|
||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Row(ref r),
|
value: UntaggedValue::Row(ref r),
|
||||||
..
|
..
|
||||||
} => r.get_data(&column.item).borrow().is_none(),
|
} if r.get_data(&column.item).borrow().is_none()
|
||||||
_ => false,
|
);
|
||||||
};
|
|
||||||
|
|
||||||
if should_add {
|
if should_add {
|
||||||
match item.insert_data_at_path(&column.item, value.clone()) {
|
match item.insert_data_at_path(&column.item, value.clone()) {
|
||||||
|
@ -140,10 +140,7 @@ impl WholeStreamCommand for RunExternalCommand {
|
|||||||
external::run_external_command(command, &mut external_context, input, &scope, is_last)
|
external::run_external_command(command, &mut external_context, input, &scope, is_last)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
match result {
|
Ok(result?.to_output_stream())
|
||||||
Ok(stream) => Ok(stream.to_output_stream()),
|
|
||||||
Err(e) => Err(e),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,10 +251,7 @@ async fn save(
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
match content {
|
shell_manager.save(&full_path, &content?, name.span)
|
||||||
Ok(save_data) => shell_manager.save(&full_path, &save_data, name.span),
|
|
||||||
Err(e) => Err(e),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn string_from(input: &[Value]) -> String {
|
fn string_from(input: &[Value]) -> String {
|
||||||
|
@ -91,10 +91,7 @@ pub fn split(
|
|||||||
crate::utils::data::split(&values, &Some(block), &name)
|
crate::utils::data::split(&values, &Some(block), &name)
|
||||||
}
|
}
|
||||||
Grouper::ByColumn(None) => {
|
Grouper::ByColumn(None) => {
|
||||||
let block = Box::new(move |_, row: &Value| match as_string(row) {
|
let block = Box::new(move |_, row: &Value| as_string(row));
|
||||||
Ok(group_key) => Ok(group_key),
|
|
||||||
Err(reason) => Err(reason),
|
|
||||||
});
|
|
||||||
|
|
||||||
crate::utils::data::split(&values, &Some(block), &name)
|
crate::utils::data::split(&values, &Some(block), &name)
|
||||||
}
|
}
|
||||||
|
@ -74,13 +74,10 @@ pub fn from_list(values: &[Value], starting_idx: usize) -> nu_table::Table {
|
|||||||
_ => ansi_term::Color::Green,
|
_ => ansi_term::Color::Green,
|
||||||
};
|
};
|
||||||
|
|
||||||
let header_bold = match config.get("header_bold") {
|
let header_bold = config
|
||||||
Some(b) => match b.as_bool() {
|
.get("header_bold")
|
||||||
Ok(b) => b,
|
.map(|x| x.as_bool().unwrap_or(true))
|
||||||
_ => true,
|
.unwrap_or(true);
|
||||||
},
|
|
||||||
_ => true,
|
|
||||||
};
|
|
||||||
|
|
||||||
TextStyle {
|
TextStyle {
|
||||||
alignment: header_align,
|
alignment: header_align,
|
||||||
|
@ -2,13 +2,10 @@ use crate::prelude::*;
|
|||||||
|
|
||||||
pub fn current_branch() -> Option<String> {
|
pub fn current_branch() -> Option<String> {
|
||||||
if let Ok(config) = crate::data::config::config(Tag::unknown()) {
|
if let Ok(config) = crate::data::config::config(Tag::unknown()) {
|
||||||
let use_starship = match config.get("use_starship") {
|
let use_starship = config
|
||||||
Some(b) => match b.as_bool() {
|
.get("use_starship")
|
||||||
Ok(b) => b,
|
.map(|x| x.is_true())
|
||||||
_ => false,
|
.unwrap_or(false);
|
||||||
},
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
if !use_starship {
|
if !use_starship {
|
||||||
#[cfg(feature = "git2")]
|
#[cfg(feature = "git2")]
|
||||||
|
@ -292,10 +292,7 @@ impl Shell for FilesystemShell {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let any_source_is_dir = sources.iter().any(|f| match f {
|
let any_source_is_dir = sources.iter().any(|f| matches!(f, Ok(f) if f.is_dir()));
|
||||||
Ok(f) => f.is_dir(),
|
|
||||||
Err(_) => false,
|
|
||||||
});
|
|
||||||
|
|
||||||
if any_source_is_dir && !recursive.item {
|
if any_source_is_dir && !recursive.item {
|
||||||
return Err(ShellError::labeled_error(
|
return Err(ShellError::labeled_error(
|
||||||
|
@ -69,10 +69,7 @@ impl EvaluatedArgs {
|
|||||||
|
|
||||||
/// Return true if the set of named arguments contains the name provided
|
/// Return true if the set of named arguments contains the name provided
|
||||||
pub fn has(&self, name: &str) -> bool {
|
pub fn has(&self, name: &str) -> bool {
|
||||||
match &self.named {
|
matches!(&self.named, Some(named) if named.contains_key(name))
|
||||||
None => false,
|
|
||||||
Some(named) => named.contains_key(name),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the corresponding Value for the named argument given, if possible
|
/// Gets the corresponding Value for the named argument given, if possible
|
||||||
|
@ -64,10 +64,7 @@ impl Ord for Dictionary {
|
|||||||
impl PartialEq<Value> for Dictionary {
|
impl PartialEq<Value> for Dictionary {
|
||||||
/// Test a dictionary against a Value for equality
|
/// Test a dictionary against a Value for equality
|
||||||
fn eq(&self, other: &Value) -> bool {
|
fn eq(&self, other: &Value) -> bool {
|
||||||
match &other.value {
|
matches!(&other.value, UntaggedValue::Row(d) if self == d)
|
||||||
UntaggedValue::Row(d) => self == d,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,48 +48,15 @@ pub fn view_text_value(value: &Value) {
|
|||||||
_ => 4u64,
|
_ => 4u64,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"colored_output" => {
|
"colored_output" => colored_output = value.as_bool().unwrap_or(true),
|
||||||
colored_output = match value.as_bool() {
|
"true_color" => true_color = value.as_bool().unwrap_or(true),
|
||||||
Ok(b) => b,
|
"header" => header = value.as_bool().unwrap_or(true),
|
||||||
_ => true,
|
"line_numbers" => line_numbers = value.as_bool().unwrap_or(true),
|
||||||
}
|
"grid" => grid = value.as_bool().unwrap_or(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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"vcs_modification_markers" => {
|
"vcs_modification_markers" => {
|
||||||
vcs_modification_markers = match value.as_bool() {
|
vcs_modification_markers = value.as_bool().unwrap_or(true)
|
||||||
Ok(b) => b,
|
|
||||||
_ => true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"snip" => {
|
|
||||||
snip = match value.as_bool() {
|
|
||||||
Ok(b) => b,
|
|
||||||
_ => true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
"snip" => snip = value.as_bool().unwrap_or(true),
|
||||||
"wrapping_mode" => {
|
"wrapping_mode" => {
|
||||||
wrapping_mode = match value.as_string() {
|
wrapping_mode = match value.as_string() {
|
||||||
Ok(s) if s.to_lowercase() == "nowrapping" => {
|
Ok(s) if s.to_lowercase() == "nowrapping" => {
|
||||||
@ -101,12 +68,7 @@ pub fn view_text_value(value: &Value) {
|
|||||||
_ => bat::WrappingMode::NoWrapping,
|
_ => bat::WrappingMode::NoWrapping,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"use_italics" => {
|
"use_italics" => use_italics = value.as_bool().unwrap_or(true),
|
||||||
use_italics = match value.as_bool() {
|
|
||||||
Ok(b) => b,
|
|
||||||
_ => true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"paging_mode" => {
|
"paging_mode" => {
|
||||||
paging_mode = match value.as_string() {
|
paging_mode = match value.as_string() {
|
||||||
Ok(s) if s.to_lowercase() == "always" => bat::PagingMode::Always,
|
Ok(s) if s.to_lowercase() == "always" => bat::PagingMode::Always,
|
||||||
@ -117,19 +79,13 @@ pub fn view_text_value(value: &Value) {
|
|||||||
_ => bat::PagingMode::QuitIfOneScreen,
|
_ => bat::PagingMode::QuitIfOneScreen,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"pager" => {
|
"pager" => pager = value.as_string().unwrap_or_else(|_| "less".to_string()),
|
||||||
pager = match value.as_string() {
|
|
||||||
Ok(s) => s,
|
|
||||||
_ => "less".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"line_ranges" => line_ranges = bat::line_range::LineRanges::all(), // not real sure what to do with this
|
"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
|
"highlight_range" => _highlight_range = "0,0", //ignore config value for now
|
||||||
"theme" => {
|
"theme" => {
|
||||||
theme = match value.as_string() {
|
theme = value
|
||||||
Ok(s) => s,
|
.as_string()
|
||||||
_ => "OneDarkHalf".to_string(),
|
.unwrap_or_else(|_| "OneDarkHalf".to_string())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user