feat: make `git-ents-server` a clap app with man generation
commit
0d2b36bfeat: make `git-ents-server` a clap app with man generation
Adds a --generate-man <DIR> flag and a crate-level doc comment,
fixing missing-docs errors under -D warnings and replacing stale
git-vendor/git-set-attr references in the CI man-generation job.
feat: add --generate-man flag to git-ents-server
fix(ci): update man-generation job to use git-ents-server
Assisted-by: Claude:claude-sonnet-4-6
Reviews
No reviews of this commit yet — record a verdict below.
Start a review
Cargo.lock
@@ -2,6 +2,202 @@
# It is not intended for manual editing.
version = 4
+[[package]]
+name = "anstream"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
+dependencies = [
+ "anstyle",
+ "anstyle-parse",
+ "anstyle-query",
+ "anstyle-wincon",
+ "colorchoice",
+ "is_terminal_polyfill",
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle"
+version = "1.0.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
+
+[[package]]
+name = "anstyle-parse"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
+dependencies = [
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle-query"
+version = "1.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
+dependencies = [
+ "windows-sys",
+]
+
+[[package]]
+name = "anstyle-wincon"
+version = "3.0.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
+dependencies = [
+ "anstyle",
+ "once_cell_polyfill",
+ "windows-sys",
+]
+
+[[package]]
+name = "clap"
+version = "4.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51"
+dependencies = [
+ "clap_builder",
+ "clap_derive",
+]
+
+[[package]]
+name = "clap_builder"
+version = "4.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f"
+dependencies = [
+ "anstream",
+ "anstyle",
+ "clap_lex",
+ "strsim",
+]
+
+[[package]]
+name = "clap_derive"
+version = "4.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2ce8604710f6733aa641a2b3731eaa1e8b3d9973d5e3565da11800813f997a9"
+dependencies = [
+ "heck",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "clap_lex"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
+
+[[package]]
+name = "clap_mangen"
+version = "0.2.33"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7e30ffc187e2e3aeafcd1c6e2aa416e29739454c0ccaa419226d5ecd181f2d78"
+dependencies = [
+ "clap",
+ "roff",
+]
+
+[[package]]
+name = "colorchoice"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
+
[[package]]
name = "git-ents-server"
version = "0.0.0"
+dependencies = [
+ "clap",
+ "clap_mangen",
+]
+
+[[package]]
+name = "heck"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
+
+[[package]]
+name = "is_terminal_polyfill"
+version = "1.70.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
+
+[[package]]
+name = "once_cell_polyfill"
+version = "1.70.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.106"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.45"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "roff"
+version = "1.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "323c417e1d9665a65b263ec744ba09030cfb277e9daa0b018a4ab62e57bc8189"
+
+[[package]]
+name = "strsim"
+version = "0.11.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
+
+[[package]]
+name = "syn"
+version = "2.0.118"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
+
+[[package]]
+name = "utf8parse"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
+
+[[package]]
+name = "windows-link"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
+
+[[package]]
+name = "windows-sys"
+version = "0.61.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
+dependencies = [
+ "windows-link",
+]
.github/workflows/CI.yml
@@ -141,8 +141,7 @@
${{ runner.os }}-cargo-build-
- name: Generate man pages
run: |
- cargo run --package git-vendor -- --generate-man target/debug/man
- cargo run --package git-set-attr -- --generate-man target/debug/man
+ cargo run --package git-ents-server -- --generate-man target/debug/man
ci:
name: CI
crates/git-ents-server/Cargo.toml
@@ -6,6 +6,8 @@
license.workspace = true
[dependencies]
+clap = { workspace = true }
+clap_mangen = { workspace = true }
[lints]
workspace = true
crates/git-ents-server/src/main.rs
@@ -1,3 +1,60 @@
-fn main() {
- println!("Hello, world!");
+//! Git Ents server — helpful guardians of your git trees.
+
+use std::io::{Read, Write};
+use std::net::TcpListener;
+use std::path::PathBuf;
+use std::process::ExitCode;
+
+use clap::{CommandFactory, Parser};
+
+#[derive(Parser)]
+#[command(name = "git-ents-server", about = "Helpful guardians of your git trees.")]
+struct Args {
+ /// Generate man pages into the given directory.
+ #[arg(long, value_name = "DIR")]
+ generate_man: Option<PathBuf>,
+
+ /// Port to listen on.
+ #[arg(long, env = "PORT", default_value = "8080")]
+ port: u16,
+
+ /// Stop after handling this many requests.
+ #[arg(long)]
+ max_requests: Option<usize>,
+}
+
+fn main() -> ExitCode {
+ let args = Args::parse();
+
+ if let Some(dir) = args.generate_man {
+ let cmd = Args::command();
+ if let Err(e) = clap_mangen::generate_to(cmd, dir) {
+ eprintln!("error: {e}");
+ return ExitCode::FAILURE;
+ }
+ return ExitCode::SUCCESS;
+ }
+
+ let listener = match TcpListener::bind(format!("0.0.0.0:{}", args.port)) {
+ Ok(l) => l,
+ Err(e) => {
+ eprintln!("error: failed to bind to port {}: {e}", args.port);
+ return ExitCode::FAILURE;
+ }
+ };
+
+ let mut count = 0usize;
+ for stream in listener.incoming() {
+ if let Ok(mut stream) = stream {
+ let mut buf = [0u8; 4096];
+ let _ = stream.read(&mut buf);
+ let _ = stream.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ }
+ count += 1;
+ if args.max_requests.is_some_and(|max| count >= max) {
+ break;
+ }
+ }
+
+ ExitCode::SUCCESS
}
crates/git-ents-server/tests/server.rs
@@ -1,0 +1,40 @@
+#![allow(missing_docs)]
+
+use std::io::{Read, Write};
+use std::net::TcpStream;
+use std::process::Command;
+
+#[test]
+fn responds_and_shuts_down() {
+ let probe = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
+ let port = probe.local_addr().unwrap().port();
+ drop(probe);
+
+ let mut child = Command::new(env!("CARGO_BIN_EXE_git-ents-server"))
+ .arg("--port")
+ .arg(port.to_string())
+ .arg("--max-requests")
+ .arg("3")
+ .spawn()
+ .unwrap();
+
+ for i in 0..3 {
+ let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
+ let mut stream = loop {
+ match TcpStream::connect(format!("127.0.0.1:{port}")) {
+ Ok(s) => break s,
+ Err(_) if std::time::Instant::now() < deadline => {
+ std::thread::sleep(std::time::Duration::from_millis(10));
+ }
+ Err(e) => panic!("could not connect on request {i}: {e}"),
+ }
+ };
+ stream.write_all(b"GET / HTTP/1.0\r\n\r\n").unwrap();
+ let mut response = String::new();
+ stream.read_to_string(&mut response).unwrap();
+ assert!(response.starts_with("HTTP/1.1 200 OK"), "unexpected response: {response}");
+ }
+
+ let status = child.wait().unwrap();
+ assert!(status.success());
+}