Add a subcommand to check server features #12

Merged
kernald merged 1 commit from server-features into main 2024-11-04 15:11:16 +11:00
6 changed files with 221 additions and 25 deletions

138
Cargo.lock generated
View file

@ -183,6 +183,12 @@ version = "3.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
[[package]]
name = "bytecount"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce"
[[package]]
name = "bytemuck"
version = "1.19.0"
@ -253,10 +259,10 @@ version = "4.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab"
dependencies = [
"heck",
"heck 0.5.0",
"proc-macro2",
"quote",
"syn",
"syn 2.0.82",
]
[[package]]
@ -513,7 +519,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.82",
]
[[package]]
@ -598,6 +604,12 @@ version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb"
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "heck"
version = "0.5.0"
@ -787,7 +799,8 @@ dependencies = [
"reqwest",
"serde",
"serde_json",
"syn",
"syn 2.0.82",
"tabled",
"tokio",
"uuid",
"vcard4",
@ -919,7 +932,7 @@ dependencies = [
"proc-macro2",
"quote",
"regex-syntax",
"syn",
"syn 2.0.82",
]
[[package]]
@ -1046,7 +1059,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.82",
]
[[package]]
@ -1079,6 +1092,17 @@ version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]]
name = "papergrid"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7419ad52a7de9b60d33e11085a0fe3df1fbd5926aa3f93d3dd53afbc9e86725"
dependencies = [
"bytecount",
"fnv",
"unicode-width",
]
[[package]]
name = "parking_lot"
version = "0.12.3"
@ -1122,7 +1146,7 @@ dependencies = [
"proc-macro2",
"proc-macro2-diagnostics",
"quote",
"syn",
"syn 2.0.82",
]
[[package]]
@ -1172,7 +1196,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "910d41a655dac3b764f1ade94821093d3610248694320cd072303a8eedcf221d"
dependencies = [
"proc-macro2",
"syn",
"syn 2.0.82",
]
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn 1.0.109",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
@ -1192,7 +1240,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.82",
"version_check",
"yansi",
]
@ -1229,7 +1277,7 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d85934a440963a69f9f04f48507ff6e7aa2952a5b2d8f96cc37fa3dd5c270f66"
dependencies = [
"heck",
"heck 0.5.0",
"http",
"indexmap",
"openapiv3",
@ -1239,7 +1287,7 @@ dependencies = [
"schemars",
"serde",
"serde_json",
"syn",
"syn 2.0.82",
"thiserror",
"typify",
"unicode-ident",
@ -1260,7 +1308,7 @@ dependencies = [
"serde_json",
"serde_tokenstream",
"serde_yaml",
"syn",
"syn 2.0.82",
]
[[package]]
@ -1487,7 +1535,7 @@ dependencies = [
"proc-macro2",
"quote",
"serde_derive_internals",
"syn",
"syn 2.0.82",
]
[[package]]
@ -1545,7 +1593,7 @@ checksum = "7e85ad2009c50b58e87caa8cd6dac16bdf511bbfb7af6c33df902396aa480fa5"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.82",
]
[[package]]
@ -1556,7 +1604,7 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.82",
]
[[package]]
@ -1589,7 +1637,7 @@ dependencies = [
"proc-macro2",
"quote",
"serde",
"syn",
"syn 2.0.82",
]
[[package]]
@ -1684,6 +1732,17 @@ version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.82"
@ -1725,6 +1784,29 @@ dependencies = [
"libc",
]
[[package]]
name = "tabled"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c9303ee60b9bedf722012ea29ae3711ba13a67c9b9ae28993838b63057cb1b"
dependencies = [
"papergrid",
"tabled_derive",
]
[[package]]
name = "tabled_derive"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf0fb8bfdc709786c154e24a66777493fb63ae97e3036d914c8666774c477069"
dependencies = [
"heck 0.4.1",
"proc-macro-error",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "tempfile"
version = "3.13.0"
@ -1764,7 +1846,7 @@ checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.82",
]
[[package]]
@ -1849,7 +1931,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.82",
]
[[package]]
@ -1989,7 +2071,7 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d59ab345b6c0d8ae9500b9ff334a4c7c0d316c1c628dc55726b95887eb8dbd11"
dependencies = [
"heck",
"heck 0.5.0",
"log",
"proc-macro2",
"quote",
@ -1998,7 +2080,7 @@ dependencies = [
"semver",
"serde",
"serde_json",
"syn",
"syn 2.0.82",
"thiserror",
"unicode-ident",
]
@ -2016,7 +2098,7 @@ dependencies = [
"serde",
"serde_json",
"serde_tokenstream",
"syn",
"syn 2.0.82",
"typify-impl",
]
@ -2056,6 +2138,12 @@ version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
[[package]]
name = "unicode-width"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
[[package]]
name = "unsafe-libyaml"
version = "0.2.11"
@ -2176,7 +2264,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn",
"syn 2.0.82",
"wasm-bindgen-shared",
]
@ -2210,7 +2298,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.82",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@ -2472,7 +2560,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.82",
]
[[package]]
@ -2492,5 +2580,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.82",
]

View file

@ -22,6 +22,7 @@ progenitor-client = "0.8.0"
regress = "0.10.1"
reqwest = { version = "0.12.8", features = ["json", "stream"] }
serde = { version = "1.0.213", features = ["derive"] }
tabled = "0.16.0"
tokio = { version = "1.41.0", features = ["full"] }
uuid = { version = "1.11.0", features = ["serde", "v4"] }
vcard4 = "0.5.2"

View file

@ -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 {},

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(())
}

View file

@ -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,
},
}