mirror of
https://github.com/nushell/nushell.git
synced 2024-11-07 17:14:23 +01:00
Make config default if broken (#482)
* Make config default if broken * Make config default if broken
This commit is contained in:
parent
90ddb23492
commit
2013e9300a
@ -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() {
|
||||
|
@ -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(
|
||||
|
@ -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 }) => {
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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())
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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') {
|
||||
|
26
src/main.rs
26
src/main.rs
@ -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) => {
|
||||
|
Loading…
Reference in New Issue
Block a user