1
0
Files
LCRConnector/kernel/lcrconn-cli/src/cli.rs

104 lines
2.7 KiB
Rust
Raw Normal View History

use std::path::{Path, PathBuf};
use clap::{Parser, ValueEnum};
/// The configuration for the app.
pub struct AppConfig {
/// The resolver for the app.
resolver: AppResolver,
/// The path to the resistor dataset file.
resistor_dataset: PathBuf,
/// The path to the capacitor dataset file.
capacitor_dataset: PathBuf,
/// The path to the inductor dataset file.
inductor_dataset: PathBuf,
}
impl AppConfig {
/// Get the resolver.
pub fn get_resolver(&self) -> &AppResolver {
&self.resolver
}
/// Get the path to the resistor dataset file.
pub fn get_resistor_dataset(&self) -> &Path {
&self.resistor_dataset
}
/// Get the path to the capacitor dataset file.
pub fn get_capacitor_dataset(&self) -> &Path {
&self.capacitor_dataset
}
/// Get the path to the inductor dataset file.
pub fn get_inductor_dataset(&self) -> &Path {
&self.inductor_dataset
}
}
/// The resolver for the app.
#[derive(Debug, Clone, ValueEnum)]
pub enum AppResolver {
/// The look-up table resolver.
#[value(name = "lut")]
Lut,
/// The BFS resolver.
#[value(name = "bfs")]
Bfs,
}
/// Get the resistor, capacitor, or inductor circuit which has the closest value
/// for your given value within at most 3 devices.
#[derive(Parser)]
#[command(
name = "LCR Connector",
version,
about = "Get the resistor, capacitor, or inductor circuit which has the closest value for your given value within at most 3 devices."
)]
struct Cli {
/// The resolver you want to use.
#[arg(short = 's', long = "resolver", required = true, value_enum)]
resolver: AppResolver,
/// The path to the resistor dataset file.
#[arg(
short = 'r',
long = "resistor",
required = true,
value_name = "RESISTOR.TXT"
)]
resistor_dataset: PathBuf,
/// The path to the inductor dataset file.
#[arg(
short = 'l',
long = "inductor",
required = true,
value_name = "INDUCTOR.TXT"
)]
inductor_dataset: PathBuf,
/// The path to the capacitor dataset file.
#[arg(
short = 'c',
long = "capacitor",
required = true,
value_name = "CAPACITOR.TXT"
)]
capacitor_dataset: PathBuf,
}
impl From<Cli> for AppConfig {
fn from(args: Cli) -> Self {
Self {
resolver: args.resolver,
resistor_dataset: args.resistor_dataset,
capacitor_dataset: args.capacitor_dataset,
inductor_dataset: args.inductor_dataset,
}
}
}
pub fn parse_args() -> AppConfig {
let args = Cli::parse();
let config = AppConfig::from(args);
config
}