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 #[command(alias = "val")]
17 Validate(ValidateCommand),
18
19 #[command(hide = true)]
21 ElevateInstallNode(ElevateInstallNodeCommand),
22
23 #[command(hide = true)]
25 ElevateUninstall(ElevateUninstallCommand),
26}
27
28#[derive(Parser, Debug)]
29pub struct ElevateInstallNodeCommand {
30 #[arg(long)]
32 pub node_json: std::path::PathBuf,
33 #[arg(long)]
35 pub archive: std::path::PathBuf,
36 #[arg(long)]
38 pub install_method: String,
39 #[arg(long)]
41 pub yes: bool,
42 #[arg(long)]
44 pub link_bins: bool,
45}
46
47#[derive(Parser, Debug)]
48pub struct ElevateUninstallCommand {
49 #[arg(long)]
51 pub manifest_json: std::path::PathBuf,
52 #[arg(long)]
54 pub yes: bool,
55}
56
57#[derive(Parser, Debug)]
58pub struct GetHashCommand {
59 #[arg(required = true)]
61 pub source: String,
62
63 #[arg(long, value_enum, default_value = "sha512")]
65 pub hash: HashAlgorithm,
66}
67
68#[derive(Parser, Debug)]
69pub struct ValidateCommand {
70 #[arg(required = true)]
72 pub file: std::path::PathBuf,
73}
74
75#[derive(clap::ValueEnum, Clone, Debug, Copy)]
76pub enum HashAlgorithm {
77 Sha512,
78 Sha256,
79}
80
81pub fn run(args: HelperCommand) -> Result<()> {
82 match args.command {
83 HelperCommands::GetHash(cmd) => {
84 let hash_type = match cmd.hash {
85 HashAlgorithm::Sha512 => crate::pkg::helper::HashType::Sha512,
86 HashAlgorithm::Sha256 => crate::pkg::helper::HashType::Sha256,
87 };
88 let hash = crate::pkg::helper::get_hash(&cmd.source, hash_type)?;
89 println!("{}", hash);
90 Ok(())
91 }
92 HelperCommands::Validate(cmd) => crate::pkg::helper::validate::run(&cmd.file),
93 HelperCommands::ElevateInstallNode(cmd) => crate::pkg::helper::elevate_install_node(&cmd),
94 HelperCommands::ElevateUninstall(cmd) => crate::pkg::helper::elevate_uninstall(&cmd),
95 }
96}