Add a subcommand to check server features

This commit is contained in:
Marc Plano-Lesay 2024-11-04 15:09:18 +11:00
parent c141153ad1
commit 0cd998a7a6
6 changed files with 221 additions and 25 deletions

View file

@ -1,3 +1,4 @@
pub mod missing_date_of_birth;
pub mod server_features;
pub mod server_version;
pub mod sync_date_of_birth;

View file

@ -0,0 +1,101 @@
use color_eyre::eyre::Result;
use tabled::{
settings::{
location::Locator,
object::{Columns, Object, Rows},
Color, Format, Style,
},
Table, Tabled,
};
use crate::Client;
#[derive(Tabled)]
struct ServerFeature {
#[tabled(rename = "Feature")]
name: &'static str,
#[tabled(rename = "Status")]
enabled: bool,
}
pub async fn server_features(client: &Client) -> Result<()> {
let response = client.get_server_features().await?;
let mut features = vec![
ServerFeature {
name: "Configuration file",
enabled: response.config_file,
},
ServerFeature {
name: "Duplicate detection",
enabled: response.duplicate_detection,
},
ServerFeature {
name: "Email",
enabled: response.email,
},
ServerFeature {
name: "Facial recognition",
enabled: response.facial_recognition,
},
ServerFeature {
name: "Import faces",
enabled: response.import_faces,
},
ServerFeature {
name: "Map",
enabled: response.map,
},
ServerFeature {
name: "OAuth",
enabled: response.oauth,
},
ServerFeature {
name: "OAuth auto-launch",
enabled: response.oauth_auto_launch,
},
ServerFeature {
name: "Password login",
enabled: response.password_login,
},
ServerFeature {
name: "Reverse geocoding",
enabled: response.reverse_geocoding,
},
ServerFeature {
name: "Search",
enabled: response.search,
},
ServerFeature {
name: "Sidecar",
enabled: response.sidecar,
},
ServerFeature {
name: "Smart search",
enabled: response.smart_search,
},
ServerFeature {
name: "Trash",
enabled: response.trash,
},
];
features.sort_by_key(|feature| feature.name);
println!(
"{}",
Table::new(features)
.with(Style::rounded())
.modify(
Columns::single(1).not(Rows::first()),
Format::content(|s| {
match s {
"true" => "Enabled".to_string(),
_ => "Disabled".to_string(),
}
})
)
.modify(Locator::content("Enabled"), Color::FG_GREEN)
.modify(Locator::content("Disabled"), Color::FG_RED)
);
Ok(())
}