soroban_cli/commands/cache/actionlog/
ls.rs

1use clap::command;
2
3use crate::config::{data, locator};
4
5#[derive(thiserror::Error, Debug)]
6pub enum Error {
7    #[error(transparent)]
8    Config(#[from] locator::Error),
9    #[error(transparent)]
10    Data(#[from] data::Error),
11}
12
13#[derive(Debug, clap::Parser, Clone)]
14#[group(skip)]
15pub struct Cmd {
16    #[command(flatten)]
17    pub config_locator: locator::Args,
18
19    #[arg(long, short = 'l')]
20    pub long: bool,
21}
22
23impl Cmd {
24    pub fn run(&self) -> Result<(), Error> {
25        let res = if self.long { self.ls_l() } else { self.ls() }?.join("\n");
26        println!("{res}");
27        Ok(())
28    }
29
30    pub fn ls(&self) -> Result<Vec<String>, Error> {
31        Ok(data::list_ulids()?
32            .iter()
33            .map(ToString::to_string)
34            .collect())
35    }
36
37    pub fn ls_l(&self) -> Result<Vec<String>, Error> {
38        Ok(data::list_actions()?
39            .iter()
40            .map(ToString::to_string)
41            .collect())
42    }
43}