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> {