1
0
mirror of https://github.com/pcvolkmer/osc-variant.git synced 2025-07-03 01:02:55 +00:00

Add sub command to calculate sha256 sum of an OSC file

This commit is contained in:
2023-09-03 18:49:28 +02:00
parent 9256e242eb
commit bfa7cc3c6b
5 changed files with 233 additions and 0 deletions

View File

@ -34,6 +34,11 @@ pub struct Cli {
#[derive(Subcommand)]
pub enum Command {
#[command(
name = "sha256sum",
about = "Berechne SHA256 Prüfsumme für die angegebene Datei"
)]
Sha256Sum { inputfile: String },
#[command(about = "Zeigt alle enthaltenen Kataloge und Formulare mit Revision an.")]
List {
inputfile: String,

View File

@ -28,12 +28,14 @@ use std::fs;
use std::fs::OpenOptions;
use std::io::Write;
use std::ops::Add;
use std::path::PathBuf;
use std::str::FromStr;
use clap::Parser;
use console::style;
use quick_xml::se::Serializer;
use serde::Serialize;
use sha256::digest;
use crate::cli::{Cli, Command};
use crate::model::onkostar_editor::OnkostarEditor;
@ -191,6 +193,24 @@ fn main() -> Result<(), Box<dyn Error>> {
data_a.print_diff(data_b, strict);
}
Command::Sha256Sum { inputfile } => {
match fs::read_to_string(inputfile.clone()) {
Ok(content) => {
println!(
"{} {}",
digest(content).as_str(),
PathBuf::from(inputfile.clone())
.canonicalize()
.unwrap_or_default()
.to_str()
.unwrap_or_default()
)
}
Err(err) => {
eprintln!("{}", FileError::Reading(inputfile, err.to_string()));
}
};
}
};
Ok(())