Make config default if broken (#482)

* Make config default if broken

* Make config default if broken
This commit is contained in:
JT 2021-12-13 16:16:51 +13:00 committed by GitHub
parent 90ddb23492
commit 2013e9300a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 47 additions and 31 deletions

View File

@ -137,7 +137,7 @@ fn string_helper(
let head = call.head;
let decimals_value: Option<i64> = call.get_flag(engine_state, stack, "decimals")?;
let column_paths: Vec<CellPath> = call.rest(engine_state, stack, 0)?;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
if let Some(decimal_val) = decimals_value {
if decimals && decimal_val.is_negative() {

View File

@ -30,7 +30,7 @@ impl Command for Debug {
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
let raw = call.has_flag("raw");
input.map(

View File

@ -79,7 +79,7 @@ fn from_csv(
let noheaders = call.has_flag("noheaders");
let separator: Option<Value> = call.get_flag(engine_state, stack, "separator")?;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
let sep = match separator {
Some(Value::String { val: s, span }) => {

View File

@ -45,7 +45,7 @@ impl Command for FromEml {
let head = call.head;
let preview_body: Option<Spanned<i64>> =
call.get_flag(engine_state, stack, "preview-body")?;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
from_eml(input, preview_body, head, &config)
}

View File

@ -34,7 +34,7 @@ impl Command for FromIcs {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
from_ics(input, head, &config)
}

View File

@ -56,7 +56,7 @@ b=2' | from ini",
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
from_ini(input, head, &config)
}
}

View File

@ -75,7 +75,7 @@ impl Command for FromJson {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let span = call.head;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
let mut string_input = input.collect_string("", &config);
string_input.push('\n');

View File

@ -267,7 +267,7 @@ fn from_ssv(
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
let name = call.head;
let noheaders = call.has_flag("noheaders");

View File

@ -73,7 +73,7 @@ b = [1, 2]' | from toml",
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let span = call.head;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
let mut string_input = input.collect_string("", &config);
string_input.push('\n');
Ok(convert_string_to_value(string_input, span)?.into_pipeline_data())

View File

@ -33,7 +33,7 @@ impl Command for FromTsv {
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
from_tsv(call, input, &config)
}
}

View File

@ -26,7 +26,7 @@ impl Command for FromUrl {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
from_url(input, head, &config)
}

View File

@ -32,7 +32,7 @@ impl Command for FromVcf {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
from_vcf(input, head, &config)
}

View File

@ -30,7 +30,7 @@ impl Command for FromXml {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
from_xml(input, head, &config)
}

View File

@ -71,7 +71,7 @@ impl Command for FromYaml {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
from_yaml(input, head, &config)
}
}
@ -100,7 +100,7 @@ impl Command for FromYml {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
from_yaml(input, head, &config)
}
}

View File

@ -60,7 +60,7 @@ impl Command for ToCsv {
let head = call.head;
let noheaders = call.has_flag("noheaders");
let separator: Option<Spanned<String>> = call.get_flag(engine_state, stack, "separator")?;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
to_csv(input, noheaders, separator, head, config)
}
}

View File

@ -299,7 +299,7 @@ fn to_html(
let partial = call.has_flag("partial");
let list = call.has_flag("list");
let theme: Option<Spanned<String>> = call.get_flag(engine_state, stack, "theme")?;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
let vec_of_values = input.into_iter().collect::<Vec<Value>>();
let headers = merge_descriptors(&vec_of_values);

View File

@ -67,7 +67,7 @@ impl Command for ToMd {
let head = call.head;
let pretty = call.has_flag("pretty");
let per_element = call.has_flag("per-element");
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
to_md(input, pretty, per_element, config, head)
}
}

View File

@ -42,7 +42,7 @@ impl Command for ToTsv {
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let noheaders = call.has_flag("noheaders");
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
to_tsv(input, noheaders, head, config)
}
}

View File

@ -61,7 +61,7 @@ impl Command for ToXml {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
let pretty: Option<Spanned<i64>> = call.get_flag(engine_state, stack, "pretty")?;
to_xml(input, head, pretty, &config)
}

View File

@ -52,7 +52,7 @@ impl Command for BuildString {
call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
let output = call
.positional
.iter()

View File

@ -37,7 +37,7 @@ impl Command for StrCollect {
) -> Result<PipelineData, ShellError> {
let separator: Option<String> = call.opt(engine_state, stack, 0)?;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
// Hmm, not sure what we actually want. If you don't use debug_string, Date comes out as human readable
// which feels funny

View File

@ -53,7 +53,7 @@ impl Command for External {
let last_expression = call.has_flag("last_expression");
let env_vars = stack.get_env_vars();
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
// Check if this is a single call to a directory, if so auto-cd
let path = nu_path::expand_path(&name.item);

View File

@ -60,7 +60,7 @@ prints out the list properly."#
let width_param: Option<String> = call.get_flag(engine_state, stack, "width")?;
let color_param: bool = call.has_flag("color");
let separator_param: Option<String> = call.get_flag(engine_state, stack, "separator")?;
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
let env_str = stack.get_env_var("LS_COLORS");
let use_grid_icons = config.use_grid_icons;

View File

@ -41,7 +41,7 @@ impl Command for Table {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let ctrlc = engine_state.ctrlc.clone();
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
let color_hm = get_color_config(&config);
let term_width = if let Some((Width(w), Height(_h))) = terminal_size::terminal_size() {

View File

@ -434,7 +434,7 @@ pub fn eval_subexpression(
// to be used later
// FIXME: the trimming of the end probably needs to live in a better place
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
let mut s = input.collect_string("", &config);
if s.ends_with('\n') {

View File

@ -13,7 +13,7 @@ use nu_parser::parse;
use nu_protocol::{
ast::Call,
engine::{EngineState, Stack, StateWorkingSet},
PipelineData, ShellError, Span, Value, CONFIG_VARIABLE_ID,
Config, PipelineData, ShellError, Span, Value, CONFIG_VARIABLE_ID,
};
use reedline::{Completer, CompletionActionHandler, DefaultPrompt, LineBuffer, Prompt};
use std::{
@ -140,6 +140,16 @@ fn main() -> Result<()> {
},
);
let config = match stack.get_config() {
Ok(config) => config,
Err(e) => {
let working_set = StateWorkingSet::new(&engine_state);
report_error(&working_set, &e);
Config::default()
}
};
match eval_block(
&engine_state,
&mut stack,
@ -147,7 +157,6 @@ fn main() -> Result<()> {
PipelineData::new(Span::unknown()),
) {
Ok(pipeline_data) => {
let config = stack.get_config()?;
for item in pipeline_data {
if let Value::Error { error } = item {
let working_set = StateWorkingSet::new(&engine_state);
@ -191,7 +200,6 @@ fn main() -> Result<()> {
PipelineData::new(Span::unknown()),
) {
Ok(pipeline_data) => {
let config = stack.get_config()?;
for item in pipeline_data {
if let Value::Error { error } = item {
let working_set = StateWorkingSet::new(&engine_state);
@ -289,7 +297,15 @@ fn main() -> Result<()> {
}
loop {
let config = stack.get_config()?;
let config = match stack.get_config() {
Ok(config) => config,
Err(e) => {
let working_set = StateWorkingSet::new(&engine_state);
report_error(&working_set, &e);
Config::default()
}
};
//Reset the ctrl-c handler
ctrlc.store(false, Ordering::SeqCst);
@ -374,7 +390,7 @@ fn print_pipeline_data(
// If the table function is in the declarations, then we can use it
// to create the table value that will be printed in the terminal
let config = stack.get_config()?;
let config = stack.get_config().unwrap_or_default();
match engine_state.find_decl("table".as_bytes()) {
Some(decl_id) => {