labadoor-csv: Integrate in main cli module

This commit is contained in:
George Kaklamanos 2023-09-17 19:54:48 +03:00
parent c8e412fa34
commit 58f9eec430
3 changed files with 25 additions and 8 deletions

View file

@ -62,11 +62,7 @@ fn auth_user(username: String, resource: String) -> Result<(), ()> {
return ret;
}
pub fn csv() {
let args: Vec<String> = std::env::args().collect();
let method = String::from(&args[1]);
let identifier = String::from(&args[2]);
let resource_shortcut = args[3].parse::<i8>().unwrap();
pub fn csv(path: String, method: String, identifier: String, resource_shortcut: i8) {
if let Ok(username) = get_username(method, identifier) {
if let Ok(resource_name) = get_resource_name(username.clone(), resource_shortcut) {

View file

@ -14,7 +14,7 @@ pub enum Command {
#[cfg(feature = "matrix")]
Matrix(Matrix),
#[cfg(feature = "csv")]
CSV,
CSV(CSV),
#[cfg(feature = "gpio")]
GPIO(GPIO),
}
@ -35,6 +35,21 @@ pub struct Matrix {
pub password: Option<String>,
}
#[cfg(feature = "csv")]
#[derive(Deserialize, Parser, Debug)]
pub struct CSV {
#[clap(short, long)]
#[arg(default_value = "Some(String::from(\"/etc/labadoor\"))")]
pub path: Option<String>,
#[clap(short, long)]
pub method: String,
#[clap(short, long)]
pub identifier: String,
// #[cfg(feature = "multiple_resources")]
#[clap(short, long)]
pub resource_shortcut: i8,
}
#[cfg(feature = "gpio")]
#[derive(Deserialize, Parser, Debug)]
pub struct GPIO {

View file

@ -19,8 +19,14 @@ fn main() {
labadoor_matrix::matrix(matrix.username.unwrap(), matrix.password.unwrap());
}
#[cfg(feature = "csv")]
cli::Command::CSV => {
labadoor_csv::csv();
cli::Command::CSV(_) => {
let csv = config.get::<cli::CSV>("csv").unwrap();
labadoor_csv::csv(
csv.path.unwrap(),
csv.method.unwrap(),
csv.identifier.unwrap(),
csv.resource_shortcut.unwrap(),
);
}
#[cfg(feature = "gpio")]
cli::Command::GPIO(_) => {