/******************************************************************************** * Prometheus exporter for monitoring network connectivity using icmp pings * * * * Copyright (C) 2019-2022 Jan Christian Grünhage * * Copyright (C) 2020-2021 Famedly GmbH * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU Affero General Public License as * * published by the Free Software Foundation, either version 3 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Affero General Public License for more details. * * * * You should have received a copy of the GNU Affero General Public License * * along with this program. If not, see . * ********************************************************************************/ use std::path::PathBuf; use clap::{ArgEnum, CommandFactory}; use clap_complete::{generate_to, Shell}; use cli::Cli; #[path = "src/cli.rs"] mod cli; fn main() -> std::io::Result<()> { let mut cli = Cli::command(); if let Some(completions_dir) = std::env::var_os("PESHMING_COMPLETIONS_DIR") { let completions_dir: PathBuf = completions_dir.into(); std::fs::create_dir_all(&completions_dir) .expect("Could not create shell completions output folder."); for shell in Shell::value_variants() { generate_to(*shell, &mut cli, "peshming", &completions_dir).unwrap_or_else(|err| { panic!( "Failed to generate shell completions for {}: {}.", shell, err ) }); } } if let Some(man_dir) = std::env::var_os("PESHMING_MAN_DIR") { let man_dir: PathBuf = man_dir.into(); std::fs::create_dir_all(&man_dir).expect("Could not create man page output folder."); let man = clap_mangen::Man::new(cli); let mut buffer: Vec = Default::default(); man.render(&mut buffer)?; std::fs::write(man_dir.join("peshming.1"), buffer)?; } Ok(()) }