labadoor-csv: Integrate in main cli module
This commit is contained in:
parent
c8e412fa34
commit
58f9eec430
3 changed files with 25 additions and 8 deletions
|
@ -62,11 +62,7 @@ fn auth_user(username: String, resource: String) -> Result<(), ()> {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn csv() {
|
pub fn csv(path: String, method: String, identifier: String, resource_shortcut: i8) {
|
||||||
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();
|
|
||||||
|
|
||||||
if let Ok(username) = get_username(method, identifier) {
|
if let Ok(username) = get_username(method, identifier) {
|
||||||
if let Ok(resource_name) = get_resource_name(username.clone(), resource_shortcut) {
|
if let Ok(resource_name) = get_resource_name(username.clone(), resource_shortcut) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub enum Command {
|
||||||
#[cfg(feature = "matrix")]
|
#[cfg(feature = "matrix")]
|
||||||
Matrix(Matrix),
|
Matrix(Matrix),
|
||||||
#[cfg(feature = "csv")]
|
#[cfg(feature = "csv")]
|
||||||
CSV,
|
CSV(CSV),
|
||||||
#[cfg(feature = "gpio")]
|
#[cfg(feature = "gpio")]
|
||||||
GPIO(GPIO),
|
GPIO(GPIO),
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,21 @@ pub struct Matrix {
|
||||||
pub password: Option<String>,
|
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")]
|
#[cfg(feature = "gpio")]
|
||||||
#[derive(Deserialize, Parser, Debug)]
|
#[derive(Deserialize, Parser, Debug)]
|
||||||
pub struct GPIO {
|
pub struct GPIO {
|
||||||
|
|
|
@ -19,8 +19,14 @@ fn main() {
|
||||||
labadoor_matrix::matrix(matrix.username.unwrap(), matrix.password.unwrap());
|
labadoor_matrix::matrix(matrix.username.unwrap(), matrix.password.unwrap());
|
||||||
}
|
}
|
||||||
#[cfg(feature = "csv")]
|
#[cfg(feature = "csv")]
|
||||||
cli::Command::CSV => {
|
cli::Command::CSV(_) => {
|
||||||
labadoor_csv::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")]
|
#[cfg(feature = "gpio")]
|
||||||
cli::Command::GPIO(_) => {
|
cli::Command::GPIO(_) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue