mirror of
https://github.com/nushell/nushell.git
synced 2025-05-30 14:50:02 +02:00
# Description Closes: #9891 I also think it's good to keep command name consistency. And moving `date format` to deprecated. # User-Facing Changes Running `date format` will lead to deprecate message: ```nushell ❯ "2021-10-22 20:00:12 +01:00" | date format Error: nu:🐚:deprecated_command × Deprecated command date format ╭─[entry #28:1:1] 1 │ "2021-10-22 20:00:12 +01:00" | date format · ─────┬───── · ╰── 'date format' is deprecated. Please use 'format date' instead. ╰──── ```
51 lines
1.4 KiB
Rust
51 lines
1.4 KiB
Rust
use nu_protocol::ast::Call;
|
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
|
use nu_protocol::{Category, PipelineData, ShellError, Signature, SyntaxShape, Type};
|
|
|
|
#[derive(Clone)]
|
|
pub struct SubCommand;
|
|
|
|
impl Command for SubCommand {
|
|
fn name(&self) -> &str {
|
|
"date format"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("date format")
|
|
.input_output_types(vec![
|
|
(Type::Date, Type::String),
|
|
(Type::String, Type::String),
|
|
])
|
|
.allow_variants_without_examples(true) // https://github.com/nushell/nushell/issues/7032
|
|
.switch("list", "lists strftime cheatsheet", Some('l'))
|
|
.optional(
|
|
"format string",
|
|
SyntaxShape::String,
|
|
"the desired date format",
|
|
)
|
|
.category(Category::Date)
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Format a given date using a format string."
|
|
}
|
|
|
|
fn search_terms(&self) -> Vec<&str> {
|
|
vec!["fmt", "strftime"]
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
_engine_state: &EngineState,
|
|
_stack: &mut Stack,
|
|
call: &Call,
|
|
_input: PipelineData,
|
|
) -> Result<PipelineData, ShellError> {
|
|
Err(nu_protocol::ShellError::DeprecatedCommand(
|
|
self.name().to_string(),
|
|
"format date".to_owned(),
|
|
call.head,
|
|
))
|
|
}
|
|
}
|