Move config to be an env var (#5230)

* Move config to be an env var

* fix fmt and tests
This commit is contained in:
JT
2022-04-19 10:28:01 +12:00
committed by GitHub
parent 409f1480f5
commit 76079d5183
52 changed files with 455 additions and 608 deletions

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().unwrap_or_default();
let config = engine_state.get_config();
let sep = match separator {
Some(Value::String { val: s, span }) => {
@ -99,7 +99,7 @@ fn from_csv(
_ => ',',
};
from_delimited_data(noheaders, sep, input, name, &config)
from_delimited_data(noheaders, sep, input, name, config)
}
#[cfg(test)]

View File

@ -45,8 +45,8 @@ 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().unwrap_or_default();
from_eml(input, preview_body, head, &config)
let config = engine_state.get_config();
from_eml(input, preview_body, head, config)
}
fn examples(&self) -> Vec<Example> {

View File

@ -28,14 +28,14 @@ impl Command for FromIcs {
fn run(
&self,
_engine_state: &EngineState,
stack: &mut Stack,
engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config().unwrap_or_default();
from_ics(input, head, &config)
let config = engine_state.get_config();
from_ics(input, head, config)
}
fn examples(&self) -> Vec<Example> {

View File

@ -50,14 +50,14 @@ b=2' | from ini",
fn run(
&self,
_engine_state: &EngineState,
stack: &mut Stack,
engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config().unwrap_or_default();
from_ini(input, head, &config)
let config = engine_state.get_config();
from_ini(input, head, config)
}
}

View File

@ -70,13 +70,13 @@ impl Command for FromJson {
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let span = call.head;
let config = stack.get_config().unwrap_or_default();
let string_input = input.collect_string("", &config)?;
let config = engine_state.get_config();
let string_input = input.collect_string("", config)?;
if string_input.is_empty() {
return Ok(PipelineData::new(span));

View File

@ -66,14 +66,14 @@ impl Command for FromNuon {
fn run(
&self,
_engine_state: &EngineState,
stack: &mut Stack,
engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config().unwrap_or_default();
let string_input = input.collect_string("", &config)?;
let config = engine_state.get_config();
let string_input = input.collect_string("", config)?;
let engine_state = EngineState::new();

View File

@ -267,7 +267,7 @@ fn from_ssv(
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let config = stack.get_config().unwrap_or_default();
let config = engine_state.get_config();
let name = call.head;
let noheaders = call.has_flag("noheaders");
@ -275,7 +275,7 @@ fn from_ssv(
let minimum_spaces: Option<Spanned<usize>> =
call.get_flag(engine_state, stack, "minimum-spaces")?;
let concat_string = input.collect_string("", &config)?;
let concat_string = input.collect_string("", config)?;
let split_at = match minimum_spaces {
Some(number) => number.item,
None => DEFAULT_MINIMUM_SPACES,

View File

@ -67,14 +67,14 @@ b = [1, 2]' | from toml",
fn run(
&self,
_engine_state: &EngineState,
stack: &mut Stack,
engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let span = call.head;
let config = stack.get_config().unwrap_or_default();
let mut string_input = input.collect_string("", &config)?;
let config = engine_state.get_config();
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

@ -28,13 +28,13 @@ impl Command for FromTsv {
fn run(
&self,
_engine_state: &EngineState,
stack: &mut Stack,
engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let config = stack.get_config().unwrap_or_default();
from_tsv(call, input, &config)
let config = engine_state.get_config();
from_tsv(call, input, config)
}
fn examples(&self) -> Vec<Example> {

View File

@ -20,14 +20,14 @@ impl Command for FromUrl {
fn run(
&self,
_engine_state: &EngineState,
stack: &mut Stack,
engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config().unwrap_or_default();
from_url(input, head, &config)
let config = engine_state.get_config();
from_url(input, head, config)
}
fn examples(&self) -> Vec<Example> {

View File

@ -26,14 +26,14 @@ impl Command for FromVcf {
fn run(
&self,
_engine_state: &EngineState,
stack: &mut Stack,
engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config().unwrap_or_default();
from_vcf(input, head, &config)
let config = engine_state.get_config();
from_vcf(input, head, config)
}
fn examples(&self) -> Vec<Example> {

View File

@ -24,14 +24,14 @@ impl Command for FromXml {
fn run(
&self,
_engine_state: &EngineState,
stack: &mut Stack,
engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config().unwrap_or_default();
from_xml(input, head, &config)
let config = engine_state.get_config();
from_xml(input, head, config)
}
fn examples(&self) -> Vec<Example> {

View File

@ -30,14 +30,14 @@ impl Command for FromYaml {
fn run(
&self,
_engine_state: &EngineState,
stack: &mut Stack,
engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config().unwrap_or_default();
from_yaml(input, head, &config)
let config = engine_state.get_config();
from_yaml(input, head, config)
}
}
@ -59,14 +59,14 @@ impl Command for FromYml {
fn run(
&self,
_engine_state: &EngineState,
stack: &mut Stack,
engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let config = stack.get_config().unwrap_or_default();
from_yaml(input, head, &config)
let config = engine_state.get_config();
from_yaml(input, head, config)
}
fn examples(&self) -> Vec<Example> {

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().unwrap_or_default();
let config = engine_state.get_config();
to_csv(input, noheaders, separator, head, config)
}
}
@ -70,7 +70,7 @@ fn to_csv(
noheaders: bool,
separator: Option<Spanned<String>>,
head: Span,
config: Config,
config: &Config,
) -> Result<PipelineData, ShellError> {
let sep = match separator {
Some(Spanned { item: s, span, .. }) => {

View File

@ -125,10 +125,10 @@ pub fn to_delimited_data(
format_name: &'static str,
input: PipelineData,
span: Span,
config: Config,
config: &Config,
) -> Result<PipelineData, ShellError> {
let value = input.into_value(span);
let output = match from_value_to_delimited_string(&value, sep, &config, span) {
let output = match from_value_to_delimited_string(&value, sep, config, span) {
Ok(mut x) => {
if noheaders {
if let Some(second_line) = x.find('\n') {

View File

@ -295,7 +295,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().unwrap_or_default();
let config = engine_state.get_config();
let vec_of_values = input.into_iter().collect::<Vec<Value>>();
let headers = merge_descriptors(&vec_of_values);
@ -365,15 +365,15 @@ fn to_html(
let inner_value = match vec_of_values.len() {
0 => String::default(),
1 => match headers {
Some(headers) => html_table(vec_of_values, headers, &config),
Some(headers) => html_table(vec_of_values, headers, config),
None => {
let value = &vec_of_values[0];
html_value(value.clone(), &config)
html_value(value.clone(), config)
}
},
_ => match headers {
Some(headers) => html_table(vec_of_values, headers, &config),
None => html_list(vec_of_values, &config),
Some(headers) => html_table(vec_of_values, headers, config),
None => html_list(vec_of_values, config),
},
};

View File

@ -59,15 +59,15 @@ impl Command for ToMd {
fn run(
&self,
_engine_state: &EngineState,
stack: &mut Stack,
engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let pretty = call.has_flag("pretty");
let per_element = call.has_flag("per-element");
let config = stack.get_config().unwrap_or_default();
let config = engine_state.get_config();
to_md(input, pretty, per_element, config, head)
}
}
@ -76,17 +76,17 @@ fn to_md(
input: PipelineData,
pretty: bool,
per_element: bool,
config: Config,
config: &Config,
head: Span,
) -> Result<PipelineData, ShellError> {
let (grouped_input, single_list) = group_by(input, head, &config);
let (grouped_input, single_list) = group_by(input, head, config);
if per_element || single_list {
return Ok(Value::string(
grouped_input
.into_iter()
.map(move |val| match val {
Value::List { .. } => table(val.into_pipeline_data(), pretty, &config),
other => fragment(other, pretty, &config),
Value::List { .. } => table(val.into_pipeline_data(), pretty, config),
other => fragment(other, pretty, config),
})
.collect::<Vec<String>>()
.join(""),
@ -94,7 +94,7 @@ fn to_md(
)
.into_pipeline_data());
}
Ok(Value::string(table(grouped_input, pretty, &config), head).into_pipeline_data())
Ok(Value::string(table(grouped_input, pretty, config), head).into_pipeline_data())
}
fn fragment(input: Value, pretty: bool, config: &Config) -> String {

View File

@ -35,14 +35,14 @@ impl Command for ToTsv {
fn run(
&self,
_engine_state: &EngineState,
stack: &mut Stack,
engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, ShellError> {
let head = call.head;
let noheaders = call.has_flag("noheaders");
let config = stack.get_config().unwrap_or_default();
let config = engine_state.get_config();
to_tsv(input, noheaders, head, config)
}
}
@ -51,7 +51,7 @@ fn to_tsv(
input: PipelineData,
noheaders: bool,
head: Span,
config: Config,
config: &Config,
) -> Result<PipelineData, ShellError> {
to_delimited_data(noheaders, '\t', "TSV", input, head, config)
}

View File

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