diff --git a/.gitignore b/.gitignore index 088ba6b..280ffcb 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,56 @@ Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk + +# # Compiled Java class files +# *.class + +# # Compiled Python bytecode +# *.py[cod] + +# # Log files +# *.log + +# # Package files +# *.jar + +# # Maven +# target/ +# dist/ + +# # JetBrains IDE +# .idea/ + +# # Unit test reports +# TEST*.xml + +# # Generated by MacOS +# .DS_Store + +# # Generated by Windows +# Thumbs.db + +# # Applications +# *.app +# *.exe +# *.war + +# # Large media files +# *.mp4 +# *.tiff +# *.avi +# *.flv +# *.mov +# *.wmv + +# # Data +# *.csv +# *.xls +# *.xlsx +# *.zip + +# # Pickle files +# .pkl + +# # Visualizations +# .png diff --git a/Cargo.toml b/Cargo.toml index 756271d..0cfbe6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/sonalake/snmp-sim-rust.git" readme = "README.md" keywords = ["snmp", "simulator"] categories = ["command-line-utilities", "simulation", "simulation::snmp"] -default-run = "snmp_sim" +default-run = "snmp-sim" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] @@ -19,7 +19,7 @@ path = "src/lib.rs" [[bin]] path = "src/main.rs" -name = "snmp_sim" +name = "snmp-sim" [[bin]] path = "src/bin/generate_spec.rs" @@ -34,6 +34,7 @@ snmp-data-parser = { path = "./crates/snmp-data-parser" } rasn-snmp = { path = "./crates/rasn/standards/snmp" } rasn-smi = { path = "./crates/rasn/standards/smi" } rasn = { path = "./crates/rasn" } +clap = { version = "3.2.6", features = ["derive"] } actix = "0.13" actix-web = { version = "4.1", default_features = false, features = [ @@ -106,6 +107,7 @@ lazy_static = "1.4" static_init = "1.0" ctor = "0.1.22" signal-child = "1" +clap = "3.2" [features] integration-tests = ["visibility"] @@ -133,3 +135,7 @@ members = [ [patch.crates-io] paperclip = { git = "https://github.com/sonalake/paperclip", branch = "master" } + +[build-dependencies] +clap_mangen = "0.1" +clap = "3.2" diff --git a/build.rs b/build.rs index d506869..89fdbd7 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,23 @@ +use std::ffi::OsString; + // generated by `sqlx migrate build-script` -fn main() { +fn main() -> std::io::Result<()> { // trigger recompilation when a new migration is added println!("cargo:rerun-if-changed=migrations"); + println!("cargo:rerun-if-env-changed=MAN_DIR"); + + let package_name: &str = env!("CARGO_PKG_NAME"); + let man_dir = std::path::PathBuf::from(std::env::var_os("MAN_DIR").map_or(OsString::from("./man"), |v| v)); + + let cmd = clap::Command::new(package_name) + .arg(clap::arg!(-n --name )) + .arg(clap::arg!(-c --count )); + + let man = clap_mangen::Man::new(cmd); + let mut buffer: Vec = Default::default(); + man.render(&mut buffer)?; + + std::fs::write(man_dir.join(format!("{}.1", package_name)), buffer)?; + + Ok(()) }