forked from extern/nushell
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 head = call.head;
|
||||||
let decimals_value: Option<i64> = call.get_flag(engine_state, stack, "decimals")?;
|
let decimals_value: Option<i64> = call.get_flag(engine_state, stack, "decimals")?;
|
||||||
let column_paths: Vec<CellPath> = call.rest(engine_state, stack, 0)?;
|
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 let Some(decimal_val) = decimals_value {
|
||||||
if decimals && decimal_val.is_negative() {
|
if decimals && decimal_val.is_negative() {
|
||||||
|
@ -30,7 +30,7 @@ impl Command for Debug {
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
let config = stack.get_config()?;
|
let config = stack.get_config().unwrap_or_default();
|
||||||
let raw = call.has_flag("raw");
|
let raw = call.has_flag("raw");
|
||||||
|
|
||||||
input.map(
|
input.map(
|
||||||
|
@ -79,7 +79,7 @@ fn from_csv(
|
|||||||
|
|
||||||
let noheaders = call.has_flag("noheaders");
|
let noheaders = call.has_flag("noheaders");
|
||||||
let separator: Option<Value> = call.get_flag(engine_state, stack, "separator")?;
|
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 {
|
let sep = match separator {
|
||||||
Some(Value::String { val: s, span }) => {
|
Some(Value::String { val: s, span }) => {
|
||||||
|
@ -45,7 +45,7 @@ impl Command for FromEml {
|
|||||||
let head = call.head;
|
let head = call.head;
|
||||||
let preview_body: Option<Spanned<i64>> =
|
let preview_body: Option<Spanned<i64>> =
|
||||||
call.get_flag(engine_state, stack, "preview-body")?;
|
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)
|
from_eml(input, preview_body, head, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ impl Command for FromIcs {
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<nu_protocol::PipelineData, ShellError> {
|
) -> Result<nu_protocol::PipelineData, ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
let config = stack.get_config()?;
|
let config = stack.get_config().unwrap_or_default();
|
||||||
from_ics(input, head, &config)
|
from_ics(input, head, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ b=2' | from ini",
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<nu_protocol::PipelineData, ShellError> {
|
) -> Result<nu_protocol::PipelineData, ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
let config = stack.get_config()?;
|
let config = stack.get_config().unwrap_or_default();
|
||||||
from_ini(input, head, &config)
|
from_ini(input, head, &config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ impl Command for FromJson {
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<nu_protocol::PipelineData, ShellError> {
|
) -> Result<nu_protocol::PipelineData, ShellError> {
|
||||||
let span = call.head;
|
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);
|
let mut string_input = input.collect_string("", &config);
|
||||||
string_input.push('\n');
|
string_input.push('\n');
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ fn from_ssv(
|
|||||||
call: &Call,
|
call: &Call,
|
||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let config = stack.get_config()?;
|
let config = stack.get_config().unwrap_or_default();
|
||||||
let name = call.head;
|
let name = call.head;
|
||||||
|
|
||||||
let noheaders = call.has_flag("noheaders");
|
let noheaders = call.has_flag("noheaders");
|
||||||
|
@ -73,7 +73,7 @@ b = [1, 2]' | from toml",
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<nu_protocol::PipelineData, ShellError> {
|
) -> Result<nu_protocol::PipelineData, ShellError> {
|
||||||
let span = call.head;
|
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);
|
let mut string_input = input.collect_string("", &config);
|
||||||
string_input.push('\n');
|
string_input.push('\n');
|
||||||
Ok(convert_string_to_value(string_input, span)?.into_pipeline_data())
|
Ok(convert_string_to_value(string_input, span)?.into_pipeline_data())
|
||||||
|
@ -33,7 +33,7 @@ impl Command for FromTsv {
|
|||||||
call: &Call,
|
call: &Call,
|
||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<nu_protocol::PipelineData, ShellError> {
|
) -> Result<nu_protocol::PipelineData, ShellError> {
|
||||||
let config = stack.get_config()?;
|
let config = stack.get_config().unwrap_or_default();
|
||||||
from_tsv(call, input, &config)
|
from_tsv(call, input, &config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ impl Command for FromUrl {
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<nu_protocol::PipelineData, ShellError> {
|
) -> Result<nu_protocol::PipelineData, ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
let config = stack.get_config()?;
|
let config = stack.get_config().unwrap_or_default();
|
||||||
from_url(input, head, &config)
|
from_url(input, head, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ impl Command for FromVcf {
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<nu_protocol::PipelineData, ShellError> {
|
) -> Result<nu_protocol::PipelineData, ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
let config = stack.get_config()?;
|
let config = stack.get_config().unwrap_or_default();
|
||||||
from_vcf(input, head, &config)
|
from_vcf(input, head, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ impl Command for FromXml {
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<nu_protocol::PipelineData, ShellError> {
|
) -> Result<nu_protocol::PipelineData, ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
let config = stack.get_config()?;
|
let config = stack.get_config().unwrap_or_default();
|
||||||
from_xml(input, head, &config)
|
from_xml(input, head, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ impl Command for FromYaml {
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<nu_protocol::PipelineData, ShellError> {
|
) -> Result<nu_protocol::PipelineData, ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
let config = stack.get_config()?;
|
let config = stack.get_config().unwrap_or_default();
|
||||||
from_yaml(input, head, &config)
|
from_yaml(input, head, &config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ impl Command for FromYml {
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<nu_protocol::PipelineData, ShellError> {
|
) -> Result<nu_protocol::PipelineData, ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
let config = stack.get_config()?;
|
let config = stack.get_config().unwrap_or_default();
|
||||||
from_yaml(input, head, &config)
|
from_yaml(input, head, &config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ impl Command for ToCsv {
|
|||||||
let head = call.head;
|
let head = call.head;
|
||||||
let noheaders = call.has_flag("noheaders");
|
let noheaders = call.has_flag("noheaders");
|
||||||
let separator: Option<Spanned<String>> = call.get_flag(engine_state, stack, "separator")?;
|
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)
|
to_csv(input, noheaders, separator, head, config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -299,7 +299,7 @@ fn to_html(
|
|||||||
let partial = call.has_flag("partial");
|
let partial = call.has_flag("partial");
|
||||||
let list = call.has_flag("list");
|
let list = call.has_flag("list");
|
||||||
let theme: Option<Spanned<String>> = call.get_flag(engine_state, stack, "theme")?;
|
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 vec_of_values = input.into_iter().collect::<Vec<Value>>();
|
||||||
let headers = merge_descriptors(&vec_of_values);
|
let headers = merge_descriptors(&vec_of_values);
|
||||||
|
@ -67,7 +67,7 @@ impl Command for ToMd {
|
|||||||
let head = call.head;
|
let head = call.head;
|
||||||
let pretty = call.has_flag("pretty");
|
let pretty = call.has_flag("pretty");
|
||||||
let per_element = call.has_flag("per-element");
|
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)
|
to_md(input, pretty, per_element, config, head)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ impl Command for ToTsv {
|
|||||||
) -> Result<nu_protocol::PipelineData, ShellError> {
|
) -> Result<nu_protocol::PipelineData, ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
let noheaders = call.has_flag("noheaders");
|
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)
|
to_tsv(input, noheaders, head, config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ impl Command for ToXml {
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<nu_protocol::PipelineData, ShellError> {
|
) -> Result<nu_protocol::PipelineData, ShellError> {
|
||||||
let head = call.head;
|
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")?;
|
let pretty: Option<Spanned<i64>> = call.get_flag(engine_state, stack, "pretty")?;
|
||||||
to_xml(input, head, pretty, &config)
|
to_xml(input, head, pretty, &config)
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ impl Command for BuildString {
|
|||||||
call: &Call,
|
call: &Call,
|
||||||
_input: PipelineData,
|
_input: PipelineData,
|
||||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||||
let config = stack.get_config()?;
|
let config = stack.get_config().unwrap_or_default();
|
||||||
let output = call
|
let output = call
|
||||||
.positional
|
.positional
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -37,7 +37,7 @@ impl Command for StrCollect {
|
|||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let separator: Option<String> = call.opt(engine_state, stack, 0)?;
|
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
|
// Hmm, not sure what we actually want. If you don't use debug_string, Date comes out as human readable
|
||||||
// which feels funny
|
// which feels funny
|
||||||
|
@ -53,7 +53,7 @@ impl Command for External {
|
|||||||
let last_expression = call.has_flag("last_expression");
|
let last_expression = call.has_flag("last_expression");
|
||||||
let env_vars = stack.get_env_vars();
|
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
|
// Check if this is a single call to a directory, if so auto-cd
|
||||||
let path = nu_path::expand_path(&name.item);
|
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 width_param: Option<String> = call.get_flag(engine_state, stack, "width")?;
|
||||||
let color_param: bool = call.has_flag("color");
|
let color_param: bool = call.has_flag("color");
|
||||||
let separator_param: Option<String> = call.get_flag(engine_state, stack, "separator")?;
|
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 env_str = stack.get_env_var("LS_COLORS");
|
||||||
let use_grid_icons = config.use_grid_icons;
|
let use_grid_icons = config.use_grid_icons;
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ impl Command for Table {
|
|||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||||
let ctrlc = engine_state.ctrlc.clone();
|
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 color_hm = get_color_config(&config);
|
||||||
|
|
||||||
let term_width = if let Some((Width(w), Height(_h))) = terminal_size::terminal_size() {
|
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
|
// to be used later
|
||||||
// FIXME: the trimming of the end probably needs to live in a better place
|
// 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);
|
let mut s = input.collect_string("", &config);
|
||||||
if s.ends_with('\n') {
|
if s.ends_with('\n') {
|
||||||
|
26
src/main.rs
26
src/main.rs
@ -13,7 +13,7 @@ use nu_parser::parse;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{EngineState, Stack, StateWorkingSet},
|
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 reedline::{Completer, CompletionActionHandler, DefaultPrompt, LineBuffer, Prompt};
|
||||||
use std::{
|
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(
|
match eval_block(
|
||||||
&engine_state,
|
&engine_state,
|
||||||
&mut stack,
|
&mut stack,
|
||||||
@ -147,7 +157,6 @@ fn main() -> Result<()> {
|
|||||||
PipelineData::new(Span::unknown()),
|
PipelineData::new(Span::unknown()),
|
||||||
) {
|
) {
|
||||||
Ok(pipeline_data) => {
|
Ok(pipeline_data) => {
|
||||||
let config = stack.get_config()?;
|
|
||||||
for item in pipeline_data {
|
for item in pipeline_data {
|
||||||
if let Value::Error { error } = item {
|
if let Value::Error { error } = item {
|
||||||
let working_set = StateWorkingSet::new(&engine_state);
|
let working_set = StateWorkingSet::new(&engine_state);
|
||||||
@ -191,7 +200,6 @@ fn main() -> Result<()> {
|
|||||||
PipelineData::new(Span::unknown()),
|
PipelineData::new(Span::unknown()),
|
||||||
) {
|
) {
|
||||||
Ok(pipeline_data) => {
|
Ok(pipeline_data) => {
|
||||||
let config = stack.get_config()?;
|
|
||||||
for item in pipeline_data {
|
for item in pipeline_data {
|
||||||
if let Value::Error { error } = item {
|
if let Value::Error { error } = item {
|
||||||
let working_set = StateWorkingSet::new(&engine_state);
|
let working_set = StateWorkingSet::new(&engine_state);
|
||||||
@ -289,7 +297,15 @@ fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loop {
|
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
|
//Reset the ctrl-c handler
|
||||||
ctrlc.store(false, Ordering::SeqCst);
|
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
|
// 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
|
// 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()) {
|
match engine_state.find_decl("table".as_bytes()) {
|
||||||
Some(decl_id) => {
|
Some(decl_id) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user