Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ uu_ls = "0.0.27"
dirs = "5.0.1"
which = "6.0.3"
uu_uname = "0.0.27"
uu_date = "0.0.27"

[package.metadata.release]
# Dont publish the binary
release = false
release = false
31 changes: 31 additions & 0 deletions crates/shell/src/commands/date.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::ffi::OsString;

use deno_task_shell::{ExecuteResult, ShellCommand, ShellCommandContext};
use futures::future::LocalBoxFuture;
use uu_date::uumain as uu_date;

pub struct DateCommand;

impl ShellCommand for DateCommand {
fn execute(&self, mut context: ShellCommandContext) -> LocalBoxFuture<'static, ExecuteResult> {
Box::pin(futures::future::ready(match execute_date(&mut context) {
Ok(_) => ExecuteResult::from_exit_code(0),
Err(exit_code) => ExecuteResult::from_exit_code(exit_code),
}))
}
}

fn execute_date(context: &mut ShellCommandContext) -> Result<(), i32> {
let mut args: Vec<OsString> = vec![OsString::from("date")];

context
.args
.iter()
.for_each(|arg| args.push(OsString::from(arg)));

let exit_code = uu_date(args.into_iter());
if exit_code != 0 {
return Err(exit_code);
}
Ok(())
}
6 changes: 6 additions & 0 deletions crates/shell/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ use uu_ls::uumain as uu_ls;

use crate::execute;

pub mod date;
pub mod uname;
pub mod which;

pub use date::DateCommand;
pub use uname::UnameCommand;
pub use which::WhichCommand;

Expand Down Expand Up @@ -44,6 +46,10 @@ pub fn get_commands() -> HashMap<String, Rc<dyn ShellCommand>> {
"uname".to_string(),
Rc::new(UnameCommand) as Rc<dyn ShellCommand>,
),
(
"date".to_string(),
Rc::new(DateCommand) as Rc<dyn ShellCommand>,
),
])
}

Expand Down
17 changes: 17 additions & 0 deletions crates/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,23 @@ async fn arithmetic() {
.await;
}

#[tokio::test]
async fn date() {
TestBuilder::new()
.command("date")
.assert_exit_code(0)
.check_stdout(false)
.run()
.await;

TestBuilder::new()
.command("date +%Y-%m-%d")
.assert_exit_code(0)
.check_stdout(false)
.run()
.await;
}

#[cfg(test)]
fn no_such_file_error_text() -> &'static str {
if cfg!(windows) {
Expand Down