1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::marker::PhantomData;
use super::BaseCommand;
use crate::error::ShiError;
use crate::shell::Shell;
use crate::Result;
#[derive(Debug)]
pub struct HistoryCommand<'a, S> {
phantom: &'a PhantomData<S>,
}
impl<'a, S> Default for HistoryCommand<'a, S> {
fn default() -> Self {
Self::new()
}
}
impl<'a, S> HistoryCommand<'a, S> {
pub fn new() -> HistoryCommand<'a, S> {
HistoryCommand {
phantom: &PhantomData,
}
}
}
impl<'a, S> BaseCommand for HistoryCommand<'a, S> {
type State = Shell<'a, S>;
fn name(&self) -> &str {
"history"
}
fn validate_args(&self, args: &[String]) -> Result<()> {
if !args.is_empty() {
return Err(ShiError::ExtraArgs { got: args.to_vec() });
}
Ok(())
}
fn execute(&self, shell: &mut Shell<S>, _: &[String]) -> Result<String> {
let history_output = shell
.rl
.history()
.iter()
.map(|h| h.to_string())
.collect::<Vec<String>>()
.join("\n\t");
Ok(format!("\t{}", history_output))
}
fn help(&self) -> String {
String::from("Prints the history of commands")
}
}