From 8510eb367dee52366840ec011cc440a673877366 Mon Sep 17 00:00:00 2001 From: Alex Page Date: Sat, 24 Jun 2023 16:04:57 -0400 Subject: [PATCH] Move clap types to their own module --- src/bin/xpkey/cli.rs | 71 +++++++++++++++++++++++++++++++++++++++++ src/bin/xpkey/main.rs | 73 ++----------------------------------------- 2 files changed, 74 insertions(+), 70 deletions(-) create mode 100644 src/bin/xpkey/cli.rs diff --git a/src/bin/xpkey/cli.rs b/src/bin/xpkey/cli.rs new file mode 100644 index 0000000..18cc56e --- /dev/null +++ b/src/bin/xpkey/cli.rs @@ -0,0 +1,71 @@ +use clap::{Args, Parser, Subcommand}; + +#[derive(Parser, Debug)] +#[command(author, about, version, long_about = None)] +pub struct Cli { + /// Enable verbose output + #[arg(short, long)] + pub verbose: bool, + + #[command(subcommand)] + pub command: Commands, +} + +#[derive(Subcommand, Clone, Debug)] +pub enum Commands { + /// Show which products/binks can be loaded + List(ListArgs), + /// Generate new product keys + Generate(GenerateArgs), + /// Validate a product key + Validate(ValidateArgs), + /// Generate a phone activation Confirmation ID from an Installation ID + #[command(name = "confid")] + ConfirmationId(ConfirmationIdArgs), +} + +#[derive(Args, Clone, Debug)] +pub struct ListArgs { + /// Optional path to load a keys.json file + #[arg(short = 'f', long = "file")] + pub keys_path: Option, +} + +#[derive(Args, Clone, Debug)] +pub struct GenerateArgs { + /// Which BINK identifier to use + #[arg(short, long, default_value = "2E")] + pub binkid: String, + + /// Channel Identifier to use + #[arg(short = 'c', long = "channel", default_value = "640")] + pub channel_id: u32, + + /// Number of keys to generate + #[arg(short = 'n', long = "number", default_value = "1")] + pub num_keys: u64, + + /// Optional path to load a keys.json file + #[arg(short = 'f', long = "file")] + pub keys_path: Option, +} + +#[derive(Args, Clone, Debug)] +pub struct ValidateArgs { + /// Which BINK identifier to use + #[arg(short, long, default_value = "2E")] + pub binkid: String, + + /// Optional path to load a keys.json file + #[arg(short = 'f', long = "file")] + pub keys_path: Option, + + /// The Product key to validate + pub key_to_check: String, +} + +#[derive(Args, Clone, Debug)] +pub struct ConfirmationIdArgs { + /// The Installation ID used to generate the Confirmation ID + pub instid: String, +} diff --git a/src/bin/xpkey/main.rs b/src/bin/xpkey/main.rs index 0b97fd6..ff1bed6 100644 --- a/src/bin/xpkey/main.rs +++ b/src/bin/xpkey/main.rs @@ -1,9 +1,10 @@ +mod cli; mod keys; use std::{fs::File, io::BufReader, path::Path}; use anyhow::{anyhow, Result}; -use clap::{Args, Parser, Subcommand}; +use clap::Parser; use keys::{Bink, Keys}; use serde_json::{from_reader, from_str}; @@ -12,75 +13,7 @@ use umskt::{ crypto::{EllipticCurve, PrivateKey}, }; -#[derive(Parser, Debug)] -#[command(author, about, version, long_about = None)] -struct Cli { - /// Enable verbose output - #[arg(short, long)] - verbose: bool, - - #[command(subcommand)] - command: Commands, -} - -#[derive(Subcommand, Clone, Debug)] -enum Commands { - /// Show which products/binks can be loaded - List(ListArgs), - /// Generate new product keys - Generate(GenerateArgs), - /// Validate a product key - Validate(ValidateArgs), - /// Generate a phone activation Confirmation ID from an Installation ID - #[command(name = "confid")] - ConfirmationId(ConfirmationIdArgs), -} - -#[derive(Args, Clone, Debug)] -struct ListArgs { - /// Specify which keys file to load - #[arg(short = 'f', long = "file")] - keys_path: Option, -} - -#[derive(Args, Clone, Debug)] -struct GenerateArgs { - /// Specify which BINK identifier to load - #[arg(short, long, default_value = "2E")] - binkid: String, - - /// Specify which Channel Identifier to use - #[arg(short = 'c', long = "channel", default_value = "640")] - channel_id: u32, - - /// Number of keys to generate - #[arg(short = 'n', long = "number", default_value = "1")] - num_keys: u64, - - /// Specify which keys file to load - #[arg(short = 'f', long = "file")] - keys_path: Option, -} - -#[derive(Args, Clone, Debug)] -struct ValidateArgs { - /// Specify which BINK identifier to load - #[arg(short, long, default_value = "2E")] - binkid: String, - - /// Specify which keys file to load - #[arg(short = 'f', long = "file")] - keys_path: Option, - - /// Product key to validate signature - key_to_check: String, -} - -#[derive(Args, Clone, Debug)] -struct ConfirmationIdArgs { - /// Installation ID used to generate confirmation ID - instid: String, -} +use cli::*; fn main() -> Result<()> { let args = Cli::parse();