Remove --separator from seq date (#7096)

This commit is contained in:
Reilly Wood 2022-11-10 23:16:44 -08:00 committed by GitHub
parent 099b571e8f
commit b650d1ef79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,12 +23,6 @@ impl Command for SeqDate {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("seq date")
.input_output_types(vec![(Type::Nothing, Type::List(Box::new(Type::String)))])
.named(
"separator",
SyntaxShape::String,
"separator character (defaults to \\n)",
Some('s'),
)
.named(
"output-format",
SyntaxShape::String,
@ -133,7 +127,6 @@ impl Command for SeqDate {
call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let separator: Option<Spanned<String>> = call.get_flag(engine_state, stack, "separator")?;
let output_format: Option<Spanned<String>> =
call.get_flag(engine_state, stack, "output-format")?;
let input_format: Option<Spanned<String>> =
@ -145,31 +138,6 @@ impl Command for SeqDate {
let days: Option<Spanned<i64>> = call.get_flag(engine_state, stack, "days")?;
let reverse = call.has_flag("reverse");
let sep: String = match separator {
Some(s) => {
if s.item == r"\t" {
'\t'.to_string()
} else if s.item == r"\n" {
'\n'.to_string()
} else if s.item == r"\r" {
'\r'.to_string()
} else {
let vec_s: Vec<char> = s.item.chars().collect();
if vec_s.is_empty() {
return Err(ShellError::GenericError(
"Expected a single separator char from --separator".to_string(),
"requires a single character string input".to_string(),
Some(s.span),
None,
Vec::new(),
));
};
vec_s.iter().collect()
}
}
_ => '\n'.to_string(),
};
let outformat = match output_format {
Some(s) => Some(Value::string(s.item, s.span)),
_ => None,
@ -203,7 +171,7 @@ impl Command for SeqDate {
}
Ok(
run_seq_dates(sep, outformat, informat, begin, end, inc, day_count, rev)?
run_seq_dates(outformat, informat, begin, end, inc, day_count, rev)?
.into_pipeline_data(),
)
}
@ -219,7 +187,6 @@ pub fn parse_date_string(s: &str, format: &str) -> Result<NaiveDate, &'static st
#[allow(clippy::too_many_arguments)]
pub fn run_seq_dates(
separator: String,
output_format: Option<Value>,
input_format: Option<Value>,
beginning_date: Option<String>,
@ -353,25 +320,19 @@ pub fn run_seq_dates(
));
}
let mut ret_str = String::from("");
let mut ret = vec![];
loop {
ret_str.push_str(&next.format(&out_format).to_string());
let date_string = &next.format(&out_format).to_string();
ret.push(Value::string(date_string, Span::test_data()));
next += Duration::days(step_size);
if is_out_of_range(next) {
break;
}
ret_str.push_str(&separator);
}
let rows: Vec<Value> = ret_str
.lines()
.map(|v| Value::string(v, Span::test_data()))
.collect();
Ok(Value::List {
vals: rows,
vals: ret,
span: Span::test_data(),
})
}