1use anyhow::Result;
7use clap::{Parser, Subcommand};
8
9#[derive(Parser, Debug)]
11pub struct HelperCommand {
12 #[command(subcommand)]
14 pub command: HelperCommands
15}
16
17#[derive(Subcommand, Debug)]
19pub enum HelperCommands {
20 GetHash(GetHashCommand),
22
23 #[command(alias = "val")]
26 Validate(ValidateCommand),
27
28 #[command(hide = true)]
31 ElevateInstallNode(ElevateInstallNodeCommand),
32
33 #[command(hide = true)]
35 ElevateUninstall(ElevateUninstallCommand)
36}
37
38#[derive(Parser, Debug)]
40pub struct ElevateInstallNodeCommand {
41 #[arg(long)]
43 pub node_json: std::path::PathBuf,
44 #[arg(long)]
46 pub archive: std::path::PathBuf,
47 #[arg(long)]
49 pub install_method: String,
50 #[arg(long)]
52 pub yes: bool,
53 #[arg(long)]
55 pub link_bins: bool
56}
57
58#[derive(Parser, Debug)]
60pub struct ElevateUninstallCommand {
61 #[arg(long)]
63 pub manifest_json: std::path::PathBuf,
64 #[arg(long)]
66 pub yes: bool
67}
68
69#[derive(Parser, Debug)]
71pub struct GetHashCommand {
72 #[arg(required = true)]
74 pub source: String,
75
76 #[arg(long, value_enum, default_value = "sha512")]
78 pub hash: HashAlgorithm
79}
80
81#[derive(Parser, Debug)]
83pub struct ValidateCommand {
84 #[arg(required = true)]
86 pub file: std::path::PathBuf
87}
88
89#[derive(clap::ValueEnum, Clone, Debug, Copy)]
91pub enum HashAlgorithm {
92 Sha512,
94 Sha256
96}
97
98pub fn run(args: HelperCommand) -> Result<()> {
104 match args.command {
105 HelperCommands::GetHash(cmd) => {
106 let hash_type = match cmd.hash {
107 HashAlgorithm::Sha512 => crate::pkg::helper::HashType::Sha512,
108 HashAlgorithm::Sha256 => crate::pkg::helper::HashType::Sha256
109 };
110 let hash = crate::pkg::helper::get_hash(&cmd.source, hash_type)?;
111 println!("{hash}");
112 Ok(())
113 }
114 HelperCommands::Validate(cmd) => {
115 crate::pkg::helper::validate::run(&cmd.file)
116 }
117 HelperCommands::ElevateInstallNode(cmd) => {
118 crate::pkg::helper::elevate_install_node(&cmd)
119 }
120 HelperCommands::ElevateUninstall(cmd) => {
121 crate::pkg::helper::elevate_uninstall(&cmd)
122 }
123 }
124}