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:
@ -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,
|
||||
|
20
src/main.rs
20
src/main.rs
@ -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(())
|
||||
|
Reference in New Issue
Block a user