generated from PlexSheep/baserepo
ccc work
This commit is contained in:
parent
4dbb075be4
commit
ff033d0ee5
|
@ -21,6 +21,10 @@ crate-type = ["cdylib", "rlib"]
|
|||
name = "pt"
|
||||
path = "src/bin/main/mod.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "ccc"
|
||||
path = "src/bin/ccc/mod.rs"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.3.11", features = ["derive"] }
|
||||
clap-num = "1.0.2"
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
//! # Executable for the math/compute submodule
|
||||
//!
|
||||
//! Compute computations with your computer!
|
||||
//!
|
||||
//! This command line tool allows you to input a mathematical expression. It will then process the
|
||||
//! expression.
|
||||
|
||||
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
|
||||
// we want docs
|
||||
#![warn(missing_docs)]
|
||||
#![warn(rustdoc::missing_crate_level_docs)]
|
||||
// we want Debug everywhere.
|
||||
#![warn(missing_debug_implementations)]
|
||||
// enable clippy's extra lints, the pedantic version
|
||||
#![warn(clippy::pedantic)]
|
||||
|
||||
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||
use pt::math::computer::*;
|
||||
use pt::logger::*;
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
use clap_num::number_range;
|
||||
use clap_verbosity_flag::{Verbosity, InfoLevel};
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
|
||||
/// short about section displayed in help
|
||||
const ABOUT_ROOT: &'static str = r##"
|
||||
Compute computations with your computer
|
||||
|
||||
This commandline tool allows you to calculate complex mathematical expressions right in your
|
||||
shell.
|
||||
"##;
|
||||
/// longer about section displayed in help, is combined with [the short help](ABOUT_ROOT)
|
||||
static LONG_ABOUT_ROOT: &'static str = r##"
|
||||
|
||||
libpt is a personal general purpose library, offering this executable, a python module and a
|
||||
dynamic library.
|
||||
"##;
|
||||
|
||||
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
#[command(
|
||||
author,
|
||||
version,
|
||||
about = ABOUT_ROOT,
|
||||
long_about = format!("{}{}", ABOUT_ROOT ,LONG_ABOUT_ROOT),
|
||||
help_template =
|
||||
r#"libpt: {version}{about-section}Author:
|
||||
{author-with-newline}
|
||||
{usage-heading} {usage}{all-args}{tab}"#
|
||||
)]
|
||||
pub struct Cli {
|
||||
// clap_verbosity_flag seems to make this a global option implicitly
|
||||
/// set a verbosity, multiple allowed (f.e. -vvv)
|
||||
#[command(flatten)]
|
||||
pub verbose: Verbosity<InfoLevel>,
|
||||
|
||||
/// show logger meta
|
||||
#[arg(short, long, global = true)]
|
||||
pub log_meta: bool,
|
||||
|
||||
/// your exporession(s)
|
||||
#[clap(trailing_var_arg=true)]
|
||||
pub expression: Vec<String>,
|
||||
}
|
||||
|
||||
//// MACROS ////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
let ll: tracing::Level = match cli.verbose.log_level().unwrap().as_str() {
|
||||
"TRACE" => tracing::Level::TRACE,
|
||||
"DEBUG" => tracing::Level::DEBUG,
|
||||
"INFO" => tracing::Level::INFO,
|
||||
"WARN" => tracing::Level::WARN,
|
||||
"ERROR" => tracing::Level::ERROR,
|
||||
_ => {
|
||||
eprintln!("'{}' is not a valid loglevel", cli.verbose.to_string());
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
if cli.log_meta {
|
||||
Logger::init_customized(
|
||||
false,
|
||||
PathBuf::from("/dev/null"),
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
ll,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
.expect("could not initialize Logger");
|
||||
} else {
|
||||
// less verbose version
|
||||
Logger::init_customized(
|
||||
false,
|
||||
PathBuf::from("/dev/null"),
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
ll,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
.expect("could not initialize Logger");
|
||||
}
|
||||
let mut expr: String = String::new();
|
||||
for part in cli.expression {
|
||||
expr += ∂
|
||||
}
|
||||
|
||||
info!("exporssion: {}", expr);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
@ -17,9 +17,8 @@
|
|||
|
||||
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||
pub mod result;
|
||||
use result::{Error, Result};
|
||||
pub use result::{Error, Result, ComputeResult};
|
||||
|
||||
use self::result::ComputeResult;
|
||||
use crate::logger::{trace, debug, info, warn, error};
|
||||
|
||||
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -78,6 +77,7 @@ impl Computer {
|
|||
/// This method only processes a single term at a time, without caching.
|
||||
pub fn compute(mut t: Term) -> Result<ComputeResult> {
|
||||
trace!("computing term {t:?}");
|
||||
return Ok(ComputeResult::from(0))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,6 +75,20 @@ impl<T: num_traits::PrimInt> From<T> for NumericResult where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: num_traits::PrimInt> From<T> for ComputeResult where
|
||||
u128: TryFrom<T>,
|
||||
u128: TryFrom<T> {
|
||||
fn from(value: T) -> Self {
|
||||
NumericResult::from(value).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NumericResult> for ComputeResult {
|
||||
fn from(value: NumericResult) -> Self {
|
||||
ComputeResult::Numerical(value)
|
||||
}
|
||||
}
|
||||
|
||||
//// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Reference in New Issue