Add a subcommand to check server features
This commit is contained in:
parent
c141153ad1
commit
0cd998a7a6
6 changed files with 221 additions and 25 deletions
|
@ -60,6 +60,9 @@ pub(crate) enum PeopleCommands {
|
|||
|
||||
#[derive(Serialize, Subcommand)]
|
||||
pub(crate) enum ServerCommands {
|
||||
/// Checks which server features are enabled
|
||||
#[serde(rename = "features")]
|
||||
Features {},
|
||||
/// Fetches the version of the server
|
||||
#[serde(rename = "version")]
|
||||
Version {},
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
pub mod missing_date_of_birth;
|
||||
pub mod server_features;
|
||||
pub mod server_version;
|
||||
pub mod sync_date_of_birth;
|
||||
|
|
101
src/commands/server_features.rs
Normal file
101
src/commands/server_features.rs
Normal 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(())
|
||||
}
|
|
@ -6,6 +6,7 @@ use clap::Parser;
|
|||
use color_eyre::eyre::{Result, WrapErr};
|
||||
use color_eyre::Section;
|
||||
use commands::missing_date_of_birth::missing_date_of_birth;
|
||||
use commands::server_features::server_features;
|
||||
use commands::server_version::server_version;
|
||||
use commands::sync_date_of_birth::sync_date_of_birth;
|
||||
use config::Config;
|
||||
|
@ -62,6 +63,7 @@ async fn main() -> Result<()> {
|
|||
}
|
||||
},
|
||||
Commands::Server { server_command } => match server_command {
|
||||
ServerCommands::Features {} => server_features(&client).await,
|
||||
ServerCommands::Version {} => server_version(&client).await,
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue