1use anyhow::Result;
2use clap::{Parser, Subcommand};
3
4#[derive(Parser, Debug)]
5pub struct HelperCommand {
6 #[command(subcommand)]
7 pub command: HelperCommands,
8}
9
10#[derive(Subcommand, Debug)]
11pub enum HelperCommands {
12 GetHash(GetHashCommand),
14}
15
16#[derive(Parser, Debug)]
17pub struct GetHashCommand {
18 #[arg(required = true)]
20 pub source: String,
21
22 #[arg(long, value_enum, default_value = "sha512")]
24 pub hash: HashAlgorithm,
25}
26
27#[derive(clap::ValueEnum, Clone, Debug, Copy)]
28pub enum HashAlgorithm {
29 Sha512,
30 Sha256,
31}
32
33pub fn run(args: HelperCommand) -> Result<()> {
34 match args.command {
35 HelperCommands::GetHash(cmd) => {
36 let hash_type = match cmd.hash {
37 HashAlgorithm::Sha512 => crate::pkg::helper::HashType::Sha512,
38 HashAlgorithm::Sha256 => crate::pkg::helper::HashType::Sha256,
39 };
40 let hash = crate::pkg::helper::get_hash(&cmd.source, hash_type)?;
41 println!("{}", hash);
42 Ok(())
43 }
44 }
45}