id3_cli/app/
backup.rs

1use crate::{
2    app::Run,
3    backup,
4    error::{Error, FileReadFailure},
5    utils::sha256_data,
6};
7use clap::Args;
8use std::{fs::read as read_file, path::PathBuf};
9
10#[derive(Debug, Args)]
11pub struct Backup {
12    /// Path to the target audio file.
13    pub target_audio: PathBuf,
14}
15
16impl Run for Backup {
17    fn run(self) -> Result<(), Error> {
18        let Backup { ref target_audio } = self;
19
20        let audio_content = read_file(target_audio).map_err(|error| FileReadFailure {
21            file: target_audio.to_path_buf(),
22            error,
23        })?;
24
25        backup::Backup::builder()
26            .source_file_path(target_audio)
27            .source_file_hash(&sha256_data(&audio_content))
28            .build()
29            .backup()?;
30
31        Ok(())
32    }
33}