version subcommand and moved verbose seperator
This commit is contained in:
parent
6acbf8de44
commit
49f765c2a5
|
@ -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)]
|
||||
|
|
|
@ -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 = <Box<Cli> 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<T>(result: Result<T, String>, args: Cli)
|
||||
where
|
||||
|
@ -26,6 +38,9 @@ pub fn proc_result<T>(result: Result<T, String>, 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<T>(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<T>(vec: Vec<T>, args: Cli)
|
|||
where
|
||||
T: Debug,
|
||||
{
|
||||
if args.verbose {
|
||||
seperator();
|
||||
}
|
||||
if args.machine {
|
||||
println!("{:#?}", vec);
|
||||
}
|
||||
|
@ -83,6 +104,9 @@ pub fn proc_result_vec<T>(res: Result<Vec<T>, String>, args: Cli)
|
|||
where
|
||||
T: Debug,
|
||||
{
|
||||
if args.verbose {
|
||||
seperator();
|
||||
}
|
||||
match res {
|
||||
Ok(vec) => {
|
||||
if args.machine {
|
||||
|
|
|
@ -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 = <Box<Cli> 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) => {
|
||||
|
|
Loading…
Reference in New Issue