version subcommand and moved verbose seperator

This commit is contained in:
Christoph J. Scherr 2023-05-17 12:50:53 +02:00
parent 6acbf8de44
commit 49f765c2a5
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
3 changed files with 30 additions and 6 deletions

View File

@ -9,6 +9,7 @@
use clap::{Args, Parser, Subcommand}; use clap::{Args, Parser, Subcommand};
use clap_num::maybe_hex; use clap_num::maybe_hex;
///////////////////////////////////////////////////////////////////////////////////////////////////
/// This is just structures for parsing Cli args /// This is just structures for parsing Cli args
#[derive(Parser, Debug, Clone)] #[derive(Parser, Debug, Clone)]
#[command(author, version, about, long_about)] // Read from `Cargo.toml` #[command(author, version, about, long_about)] // Read from `Cargo.toml`
@ -38,6 +39,8 @@ pub enum Commands {
Binary(BinaryCommand), Binary(BinaryCommand),
/// Use custom algorithms /// Use custom algorithms
Algo(AlgoCommand), Algo(AlgoCommand),
/// Print version
Version,
} }
#[derive(Args, Clone, Debug, PartialEq, Eq)] #[derive(Args, Clone, Debug, PartialEq, Eq)]

View File

@ -12,13 +12,25 @@ use crate::cplex::cli::Cli;
use std::fmt::{Debug, LowerHex}; use std::fmt::{Debug, LowerHex};
use clap::CommandFactory;
use num::Integer; use num::Integer;
///////////////////////////////////////////////////////////////////////////////////////////////////
/// print the version
pub fn version() {
let b = <Box<Cli> as CommandFactory>::command();
println!("{} {}", b.get_name(), b.get_version().unwrap());
return;
}
/// print a seperator /// print a seperator
pub fn seperator() { pub fn seperator() {
println!("{:=<120}", '='); println!("{:=<120}", '=');
} }
///////////////////////////////////////////////////////////////////////////////////////////////////
/// process a result with some int /// process a result with some int
pub fn proc_result<T>(result: Result<T, String>, args: Cli) pub fn proc_result<T>(result: Result<T, String>, args: Cli)
where where
@ -26,6 +38,9 @@ pub fn proc_result<T>(result: Result<T, String>, args: Cli)
T: Integer, T: Integer,
T: LowerHex T: LowerHex
{ {
if args.verbose {
seperator();
}
match result { match result {
Ok(res) => { Ok(res) => {
if args.machine { if args.machine {
@ -55,6 +70,9 @@ pub fn proc_num<T>(num: T, args: Cli)
T: Integer, T: Integer,
T: LowerHex T: LowerHex
{ {
if args.verbose {
seperator();
}
if args.machine { if args.machine {
println!("{:#x}", num); println!("{:#x}", num);
} }
@ -69,6 +87,9 @@ pub fn proc_vec<T>(vec: Vec<T>, args: Cli)
where where
T: Debug, T: Debug,
{ {
if args.verbose {
seperator();
}
if args.machine { if args.machine {
println!("{:#?}", vec); println!("{:#?}", vec);
} }
@ -83,6 +104,9 @@ pub fn proc_result_vec<T>(res: Result<Vec<T>, String>, args: Cli)
where where
T: Debug, T: Debug,
{ {
if args.verbose {
seperator();
}
match res { match res {
Ok(vec) => { Ok(vec) => {
if args.machine { if args.machine {

View File

@ -34,14 +34,11 @@ use num_bigint;
/// This function is the entrypoint of the binary. It parses Commandline options and calls the /// 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. /// internal functions with the corresponding values, then shows the results to the user.
pub fn main() { pub fn main() {
//let b = <Box<Cli> as CommandFactory>::command();
//dbg!(b.get_author());
//return;
let args = Cli::parse(); let args = Cli::parse();
if args.verbose {
cplex::printing::seperator();
}
match args.clone().command { match args.clone().command {
Commands::Version => {
cplex::printing::version();
}
Commands::Math(action) => { Commands::Math(action) => {
match action.action { match action.action {
MathActions::Modexp(mod_exp_args) => { MathActions::Modexp(mod_exp_args) => {