chore(doc): Docu & tests for rosenpass/src/main.rs

This commit is contained in:
Karolin Varner
2024-12-08 01:17:13 +01:00
parent f04cff6d57
commit 32ebd18107
2 changed files with 21 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
//! For the main function
use clap::CommandFactory; use clap::CommandFactory;
use clap::Parser; use clap::Parser;
use clap_mangen::roff::{roman, Roff}; use clap_mangen::roff::{roman, Roff};
@@ -5,6 +7,7 @@ use log::error;
use rosenpass::cli::CliArgs; use rosenpass::cli::CliArgs;
use std::process::exit; use std::process::exit;
/// Printing custom man sections when generating the man page
fn print_custom_man_section(section: &str, text: &str, file: &mut std::fs::File) { fn print_custom_man_section(section: &str, text: &str, file: &mut std::fs::File) {
let mut roff = Roff::default(); let mut roff = Roff::default();
roff.control("SH", [section]); roff.control("SH", [section]);
@@ -13,6 +16,8 @@ fn print_custom_man_section(section: &str, text: &str, file: &mut std::fs::File)
} }
/// Catches errors, prints them through the logger, then exits /// Catches errors, prints them through the logger, then exits
///
/// The bulk of the command line logic is handled inside [crate::cli::CliArgs::run].
pub fn main() { pub fn main() {
// parse CLI arguments // parse CLI arguments
let args = CliArgs::parse(); let args = CliArgs::parse();
@@ -81,21 +86,27 @@ pub fn main() {
} }
} }
} }
/// Custom main page section: Exit Status
static EXIT_STATUS_MAN: &str = r" static EXIT_STATUS_MAN: &str = r"
The rosenpass utility exits 0 on success, and >0 if an error occurs."; The rosenpass utility exits 0 on success, and >0 if an error occurs.";
/// Custom main page section: See also.
static SEE_ALSO_MAN: &str = r" static SEE_ALSO_MAN: &str = r"
rp(1), wg(1) rp(1), wg(1)
Karolin Varner, Benjamin Lipp, Wanja Zaeske, and Lisa Schmidt, Rosenpass, https://rosenpass.eu/whitepaper.pdf, 2023."; Karolin Varner, Benjamin Lipp, Wanja Zaeske, and Lisa Schmidt, Rosenpass, https://rosenpass.eu/whitepaper.pdf, 2023.";
/// Custom main page section: Standards.
static STANDARDS_MAN: &str = r" static STANDARDS_MAN: &str = r"
This tool is the reference implementation of the Rosenpass protocol, as This tool is the reference implementation of the Rosenpass protocol, as
specified within the whitepaper referenced above."; specified within the whitepaper referenced above.";
/// Custom main page section: Authors.
static AUTHORS_MAN: &str = r" static AUTHORS_MAN: &str = r"
Rosenpass was created by Karolin Varner, Benjamin Lipp, Wanja Zaeske, Marei Rosenpass was created by Karolin Varner, Benjamin Lipp, Wanja Zaeske, Marei
Peischl, Stephan Ajuvo, and Lisa Schmidt."; Peischl, Stephan Ajuvo, and Lisa Schmidt.";
/// Custom main page section: Bugs.
static BUGS_MAN: &str = r" static BUGS_MAN: &str = r"
The bugs are tracked at https://github.com/rosenpass/rosenpass/issues."; The bugs are tracked at https://github.com/rosenpass/rosenpass/issues.";

View File

@@ -0,0 +1,10 @@
#[test]
fn main_fn_prints_errors() -> anyhow::Result<()> {
let out = test_bin::get_test_bin("rosenpass")
.args(["exchange-config", "/"])
.output()?;
assert!(!out.status.success());
assert!(String::from_utf8(out.stderr)?.contains("Is a directory (os error 21)"));
Ok(())
}