From 49f765c2a5f862d49d5e95bfba2c9e88a6a5ae7e Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Wed, 17 May 2023 12:50:53 +0200 Subject: [PATCH] version subcommand and moved verbose seperator --- src/cplex/cli.rs | 3 +++ src/cplex/printing.rs | 24 ++++++++++++++++++++++++ src/main.rs | 9 +++------ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/cplex/cli.rs b/src/cplex/cli.rs index e9740f3..a3284c8 100644 --- a/src/cplex/cli.rs +++ b/src/cplex/cli.rs @@ -9,6 +9,7 @@ use clap::{Args, Parser, Subcommand}; use clap_num::maybe_hex; +/////////////////////////////////////////////////////////////////////////////////////////////////// /// This is just structures for parsing Cli args #[derive(Parser, Debug, Clone)] #[command(author, version, about, long_about)] // Read from `Cargo.toml` @@ -38,6 +39,8 @@ pub enum Commands { Binary(BinaryCommand), /// Use custom algorithms Algo(AlgoCommand), + /// Print version + Version, } #[derive(Args, Clone, Debug, PartialEq, Eq)] diff --git a/src/cplex/printing.rs b/src/cplex/printing.rs index 04b9da4..0dc6c82 100644 --- a/src/cplex/printing.rs +++ b/src/cplex/printing.rs @@ -12,13 +12,25 @@ use crate::cplex::cli::Cli; use std::fmt::{Debug, LowerHex}; +use clap::CommandFactory; use num::Integer; +/////////////////////////////////////////////////////////////////////////////////////////////////// + +/// print the version +pub fn version() { + let b = as CommandFactory>::command(); + println!("{} {}", b.get_name(), b.get_version().unwrap()); + return; +} + /// print a seperator pub fn seperator() { println!("{:=<120}", '='); } +/////////////////////////////////////////////////////////////////////////////////////////////////// + /// process a result with some int pub fn proc_result(result: Result, args: Cli) where @@ -26,6 +38,9 @@ pub fn proc_result(result: Result, args: Cli) T: Integer, T: LowerHex { + if args.verbose { + seperator(); + } match result { Ok(res) => { if args.machine { @@ -55,6 +70,9 @@ pub fn proc_num(num: T, args: Cli) T: Integer, T: LowerHex { + if args.verbose { + seperator(); + } if args.machine { println!("{:#x}", num); } @@ -69,6 +87,9 @@ pub fn proc_vec(vec: Vec, args: Cli) where T: Debug, { + if args.verbose { + seperator(); + } if args.machine { println!("{:#?}", vec); } @@ -83,6 +104,9 @@ pub fn proc_result_vec(res: Result, String>, args: Cli) where T: Debug, { + if args.verbose { + seperator(); + } match res { Ok(vec) => { if args.machine { diff --git a/src/main.rs b/src/main.rs index abc0569..06aed42 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,14 +34,11 @@ use num_bigint; /// This function is the entrypoint of the binary. It parses Commandline options and calls the /// internal functions with the corresponding values, then shows the results to the user. pub fn main() { - //let b = as CommandFactory>::command(); - //dbg!(b.get_author()); - //return; let args = Cli::parse(); - if args.verbose { - cplex::printing::seperator(); - } match args.clone().command { + Commands::Version => { + cplex::printing::version(); + } Commands::Math(action) => { match action.action { MathActions::Modexp(mod_exp_args) => {