borgbackup/sync/
list.rs

1use log::{debug, info};
2
3use crate::common::{list_fmt_args, list_parse_output, CommonOptions, ListOptions};
4use crate::errors::ListError;
5use crate::output::list::ListRepository;
6use crate::sync::execute_borg;
7
8/// The entry point for the borg list command
9///
10/// **Parameter**:
11/// - `options`: Reference to [ListOptions]
12/// - `common_options`: The [CommonOptions] that can be applied to any command
13pub fn list(
14    options: &ListOptions,
15    common_options: &CommonOptions,
16) -> Result<ListRepository, ListError> {
17    let local_path = common_options.local_path.as_ref().map_or("borg", |x| x);
18
19    let args = list_fmt_args(options, common_options);
20    debug!("Calling borg: {local_path} {args}");
21
22    let args = shlex::split(&args).ok_or(ListError::ShlexError)?;
23    let res = execute_borg(local_path, args, &options.passphrase)?;
24
25    let list_output = list_parse_output(res)?;
26
27    info!("Finished listing repository");
28
29    Ok(list_output)
30}