Skip to main content

quartz_cli/action/
history.rs

1use crate::{history::History, Ctx, QuartzResult};
2
3#[derive(clap::Args, Debug)]
4pub struct Args {
5    /// Maximum number of requests to be listed
6    #[arg(short = 'n', long, value_name = "N")]
7    max_count: Option<usize>,
8}
9
10pub fn cmd(ctx: &Ctx, args: Args) -> QuartzResult {
11    let history = History::new(ctx)?;
12    let mut count = 0;
13    let max_count = args.max_count.unwrap_or(usize::MAX);
14
15    let mut output = String::new();
16    for entry in history.entries(ctx) {
17        if count >= max_count {
18            break;
19        }
20
21        count += 1;
22        if count != 1 {
23            // Separation between two entries
24            output.push('\n');
25        }
26
27        output.push_str(&format!("{entry}\n"));
28    }
29
30    ctx.paginate(output.as_bytes())?;
31
32    Ok(())
33}