2021-12-16 01:13:03 +01:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2021-02-13 04:46:22 +01:00
|
|
|
use std::env;
|
2023-11-02 01:55:32 +01:00
|
|
|
use std::io::Error;
|
2021-02-13 04:46:22 +01:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2022-06-11 07:24:29 +02:00
|
|
|
use clap::{CommandFactory, Parser};
|
|
|
|
use clap_complete::{generate_to, Shell};
|
2023-07-05 01:13:06 +02:00
|
|
|
use url::Url;
|
2022-10-01 08:08:51 +02:00
|
|
|
use uuid::Uuid;
|
2021-02-13 04:46:22 +01:00
|
|
|
|
|
|
|
include!("src/opt/ssh_authorizedkeys.rs");
|
|
|
|
include!("src/opt/kanidm.rs");
|
|
|
|
|
2023-11-02 01:55:32 +01:00
|
|
|
fn main() -> Result<(), Error> {
|
2023-07-31 14:27:21 +02:00
|
|
|
profiles::apply_profile();
|
|
|
|
|
2024-02-27 10:25:02 +01:00
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
|
|
println!("cargo:rerun-if-env-changed=OUT_DIR");
|
|
|
|
println!("cargo:rerun-if-changed=src/opt/kanidm.rs");
|
|
|
|
println!("cargo:rerun-if-changed=src/opt/ssh_authorizedkeys.rs");
|
2021-02-13 04:46:22 +01:00
|
|
|
let outdir = match env::var_os("OUT_DIR") {
|
2023-11-02 01:55:32 +01:00
|
|
|
None => return Ok(()),
|
2021-02-13 04:46:22 +01:00
|
|
|
Some(outdir) => outdir,
|
|
|
|
};
|
|
|
|
|
2021-10-10 00:44:58 +02:00
|
|
|
let comp_dir = PathBuf::from(outdir)
|
|
|
|
.ancestors()
|
2021-12-16 01:13:03 +01:00
|
|
|
.nth(2)
|
2021-10-10 00:44:58 +02:00
|
|
|
.map(|p| p.join("completions"))
|
|
|
|
.expect("Unable to process completions path");
|
|
|
|
|
|
|
|
if !comp_dir.exists() {
|
|
|
|
std::fs::create_dir(&comp_dir).expect("Unable to create completions dir");
|
|
|
|
}
|
|
|
|
|
2024-09-04 01:50:59 +02:00
|
|
|
for shell in [Shell::Bash, Shell::Elvish, Shell::Fish, Shell::Zsh] {
|
2023-11-02 01:55:32 +01:00
|
|
|
generate_to(
|
|
|
|
shell,
|
|
|
|
&mut SshAuthorizedOpt::command(),
|
|
|
|
"kanidm_ssh_authorizedkeys_direct",
|
|
|
|
comp_dir.clone(),
|
|
|
|
)?;
|
|
|
|
|
|
|
|
generate_to(
|
|
|
|
shell,
|
|
|
|
&mut KanidmClientParser::command(),
|
|
|
|
"kanidm",
|
|
|
|
comp_dir.clone(),
|
|
|
|
)?;
|
|
|
|
}
|
|
|
|
Ok(())
|
2021-02-13 04:46:22 +01:00
|
|
|
}
|