A better Rust ATProto crate

man page generation

Orual ee92b831 91bbdf40

+109 -18
+27
Cargo.lock
··· 708 708 ] 709 709 710 710 [[package]] 711 + name = "clap_complete" 712 + version = "4.5.59" 713 + source = "registry+https://github.com/rust-lang/crates.io-index" 714 + checksum = "2348487adcd4631696ced64ccdb40d38ac4d31cae7f2eec8817fcea1b9d1c43c" 715 + dependencies = [ 716 + "clap", 717 + ] 718 + 719 + [[package]] 711 720 name = "clap_derive" 712 721 version = "4.5.49" 713 722 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 724 733 version = "0.7.6" 725 734 source = "registry+https://github.com/rust-lang/crates.io-index" 726 735 checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" 736 + 737 + [[package]] 738 + name = "clap_mangen" 739 + version = "0.2.30" 740 + source = "registry+https://github.com/rust-lang/crates.io-index" 741 + checksum = "263c8214a8e0cb8129f3c62036c50e9c6e15c7bd364c42e0437c492b9293f778" 742 + dependencies = [ 743 + "clap", 744 + "roff", 745 + ] 727 746 728 747 [[package]] 729 748 name = "color_quant" ··· 2451 2470 dependencies = [ 2452 2471 "async-trait", 2453 2472 "clap", 2473 + "clap_complete", 2474 + "clap_mangen", 2454 2475 "glob", 2455 2476 "heck 0.5.0", 2456 2477 "jacquard-api 0.6.0 (git+https://tangled.org/@nonbinary.computer/jacquard)", ··· 3873 3894 "untrusted", 3874 3895 "windows-sys 0.52.0", 3875 3896 ] 3897 + 3898 + [[package]] 3899 + name = "roff" 3900 + version = "0.2.2" 3901 + source = "registry+https://github.com/rust-lang/crates.io-index" 3902 + checksum = "88f8660c1ff60292143c98d08fc6e2f654d722db50410e3f3797d40baaf9d8f3" 3876 3903 3877 3904 [[package]] 3878 3905 name = "rouille"
+2
Cargo.toml
··· 23 23 [workspace.dependencies] 24 24 # CLI 25 25 clap = { version = "4.5", features = ["derive"] } 26 + clap_complete = "4.5" 27 + clap_mangen = "0.2" 26 28 27 29 # Serialization 28 30 serde = { version = "1.0", features = ["derive"] }
+5
crates/jacquard-lexicon/Cargo.toml
··· 47 47 [dev-dependencies] 48 48 tempfile = { version = "3.23.0" } 49 49 50 + [build-dependencies] 51 + clap.workspace = true 52 + clap_complete.workspace = true 53 + clap_mangen.workspace = true 54 + 50 55 [package.metadata.binstall] 51 56 pkg-url = "https://github.com/rsform/jacquard/releases/download/v{ version }/{ name }_{ target }_v{ version }{ archive-suffix }" 52 57 bin-dir = "{ name }_{ target }_v{ version }/{ bin }{ binary-ext }"
+39
crates/jacquard-lexicon/build.rs
··· 1 + use clap::CommandFactory; 2 + use clap_complete::{generate_to, shells}; 3 + use clap_mangen::Man; 4 + use std::env; 5 + use std::fs; 6 + use std::io::Result; 7 + use std::path::PathBuf; 8 + 9 + #[path = "src/cli.rs"] 10 + mod cli; 11 + 12 + fn main() -> Result<()> { 13 + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap_or_else(|_| ".".to_string())); 14 + let mut cmd = cli::LexFetchArgs::command(); 15 + 16 + // Generate man page 17 + let man_dir = out_dir.join("man"); 18 + fs::create_dir_all(&man_dir)?; 19 + 20 + let man = Man::new(cmd.clone()); 21 + let mut man_buffer = Vec::new(); 22 + man.render(&mut man_buffer)?; 23 + fs::write(man_dir.join("lex-fetch.1"), man_buffer)?; 24 + 25 + // Generate shell completions 26 + let comp_dir = out_dir.join("completions"); 27 + fs::create_dir_all(&comp_dir)?; 28 + 29 + generate_to(shells::Bash, &mut cmd, "lex-fetch", &comp_dir)?; 30 + generate_to(shells::Fish, &mut cmd, "lex-fetch", &comp_dir)?; 31 + generate_to(shells::Zsh, &mut cmd, "lex-fetch", &comp_dir)?; 32 + 33 + println!( 34 + "cargo:warning=Generated man page and completions to {:?}", 35 + out_dir 36 + ); 37 + 38 + Ok(()) 39 + }
+2 -17
crates/jacquard-lexicon/src/bin/lex_fetch.rs
··· 1 1 use clap::Parser; 2 + use jacquard_lexicon::cli::LexFetchArgs; 2 3 use jacquard_lexicon::codegen::CodeGenerator; 3 4 use jacquard_lexicon::corpus::LexiconCorpus; 4 5 use jacquard_lexicon::fetch::{Config, Fetcher}; 5 6 use miette::{IntoDiagnostic, Result}; 6 7 use std::path::PathBuf; 7 8 8 - #[derive(Parser, Debug)] 9 - #[command(author, version, about = "Fetch Lexicon schemas from various sources")] 10 - struct Args { 11 - /// Path to KDL config file 12 - #[arg(short = 'c', long, default_value = "lexicons.kdl")] 13 - config: PathBuf, 14 - 15 - /// Skip code generation step 16 - #[arg(long)] 17 - no_codegen: bool, 18 - 19 - /// Verbose output 20 - #[arg(short = 'v', long)] 21 - verbose: bool, 22 - } 23 - 24 9 #[tokio::main] 25 10 async fn main() -> Result<()> { 26 - let args = Args::parse(); 11 + let args = LexFetchArgs::parse(); 27 12 28 13 if args.verbose { 29 14 println!("Reading config from {:?}...", args.config);
+18
crates/jacquard-lexicon/src/cli.rs
··· 1 + use clap::Parser; 2 + use std::path::PathBuf; 3 + 4 + #[derive(Parser, Debug)] 5 + #[command(author, version, about = "Fetch Lexicon schemas from various sources")] 6 + pub struct LexFetchArgs { 7 + /// Path to KDL config file 8 + #[arg(short = 'c', long, default_value = "lexicons.kdl")] 9 + pub config: PathBuf, 10 + 11 + /// Skip code generation step 12 + #[arg(long)] 13 + pub no_codegen: bool, 14 + 15 + /// Verbose output 16 + #[arg(short = 'v', long)] 17 + pub verbose: bool, 18 + }
+1
crates/jacquard-lexicon/src/lib.rs
··· 36 36 //! - [`fetch`] - Ingests lexicons from git, atproto, http fetch, and other sources 37 37 //! - [`fs`] - Filesystem utilities for lexicon storage 38 38 39 + pub mod cli; 39 40 pub mod codegen; 40 41 pub mod corpus; 41 42 pub mod error;
+15 -1
nix/modules/rust.nix
··· 78 78 crane = { 79 79 args = { 80 80 buildInputs = commonBuildInputs; 81 + doCheck = false; # Tests require lexicon corpus files not available in nix build 82 + postInstall = '' 83 + # Install man pages 84 + if [ -d "$OUT_DIR/man" ]; then 85 + install -Dm644 $OUT_DIR/man/*.1 -t $out/share/man/man1/ 86 + fi 87 + 88 + # Install shell completions 89 + if [ -d "$OUT_DIR/completions" ]; then 90 + install -Dm644 $OUT_DIR/completions/lex-fetch.bash $out/share/bash-completion/completions/lex-fetch 91 + install -Dm644 $OUT_DIR/completions/lex-fetch.fish $out/share/fish/vendor_completions.d/lex-fetch.fish 92 + install -Dm644 $OUT_DIR/completions/_lex-fetch $out/share/zsh/site-functions/_lex-fetch 93 + fi 94 + ''; 81 95 }; 82 96 }; 83 97 }; ··· 123 137 }; 124 138 }; 125 139 }; 126 - packages.default = self'.packages.jacquard; 140 + packages.default = self'.packages.jacquard-lexicon; 127 141 }; 128 142 }