Browse Source

feat: add time command

main
fdai7375 2 years ago
parent
commit
ecf1dd01c9
  1. 2
      src/builtins/mod.rs
  2. 15
      src/builtins/time.rs

2
src/builtins/mod.rs

@ -13,6 +13,7 @@ mod pwd;
mod quote; mod quote;
mod segfault; mod segfault;
mod sus; mod sus;
mod time;
pub struct BuiltinConfig { pub struct BuiltinConfig {
pub prompt_style: PromptStyle, pub prompt_style: PromptStyle,
@ -43,6 +44,7 @@ const BUILTINS: Lazy<Vec<(&str, Box<dyn Builtin>)>> = Lazy::new(|| {
("segfault", Box::new(segfault::Segfault)), ("segfault", Box::new(segfault::Segfault)),
("sus", Box::new(sus::Sus)), ("sus", Box::new(sus::Sus)),
("quote", Box::new(quote::Quote)), ("quote", Box::new(quote::Quote)),
("time", Box::new(time::Time)),
] ]
}); });

15
src/builtins/time.rs

@ -0,0 +1,15 @@
use chrono::{DateTime, Local, TimeZone};
use crate::error::ShellError;
use super::{Builtin, BuiltinConfig};
pub struct Time;
impl Builtin for Time {
fn execute(&mut self, _: &mut BuiltinConfig, _: Vec<String>) -> Result<(), ShellError> {
let time = Local::now();
println!("{time}");
Ok(())
}
}
Loading…
Cancel
Save