File tree Expand file tree Collapse file tree 4 files changed +76
-2
lines changed
Expand file tree Collapse file tree 4 files changed +76
-2
lines changed Original file line number Diff line number Diff line change @@ -11,4 +11,5 @@ readme = "README.md"
1111[dependencies ]
1212clap = { version = " 4.0" , features = [" derive" ] }
1313flate2 = " 1.0"
14- regex = " 1.5"
14+ regex = " 1.5"
15+ clap_mangen = " 0.2"
Original file line number Diff line number Diff line change @@ -36,3 +36,33 @@ cd spars; cargo install --path .
3636```
3737
3838Precompiled binaries are also available in the release
39+
40+ ## Man Pages
41+
42+ The tool includes man pages (documentation) that can be generated and installed after installation:
43+
44+ ``` bash
45+ # generate manpages
46+ spars generate-manpages --outdir /tmp/spars-man
47+
48+ # install man pages (requires sudo)
49+ # note that this path may be different on different systems
50+ sudo cp /tmp/spars-man/* .1 /usr/local/share/man/man1/
51+
52+ # on linux, update the manual page cache by running mandb
53+ sudo mandb
54+ ```
55+
56+ Once installed, you can view the documentation with:
57+
58+ ``` bash
59+ man spars # main command documentation
60+ man spars-stats # stats subcommand
61+ man spars-subset # subset subcommand
62+ ```
63+
64+ Alternatively, you can view the man pages directly without installation:
65+
66+ ``` bash
67+ man /tmp/spars-man/spars.1
68+ ```
Original file line number Diff line number Diff line change 11use clap:: { Parser , Subcommand , ArgGroup } ;
22use std:: error:: Error ;
3-
3+ use std :: path :: PathBuf ;
44mod stats;
55mod subset;
66mod io_utils;
7+ mod man;
78
89#[ derive( Parser ) ]
910#[ command(
@@ -65,6 +66,20 @@ enum Commands {
6566 #[ arg( long) ]
6667 no_reindex : bool ,
6768 } ,
69+
70+ #[ command(
71+ name = "generate-manpages" ,
72+ about = "Generate man pages" ,
73+ hide = true // Hide from normal help output
74+ ) ]
75+ GenerateManPages {
76+ #[ arg(
77+ short,
78+ long,
79+ help = "Output directory for man pages"
80+ ) ]
81+ outdir : PathBuf ,
82+ } ,
6883}
6984
7085fn main ( ) -> Result < ( ) , Box < dyn Error > > {
@@ -90,6 +105,9 @@ fn main() -> Result<(), Box<dyn Error>> {
90105 no_reindex,
91106 ) ?;
92107 }
108+ Commands :: GenerateManPages { outdir } => {
109+ man:: generate_manpages ( outdir) ?;
110+ } ,
93111 }
94112
95113 Ok ( ( ) )
Original file line number Diff line number Diff line change 1+ use clap:: CommandFactory ;
2+ use clap_mangen:: Man ;
3+ use std:: fs:: File ;
4+ use std:: path:: Path ;
5+ use std:: io:: Result ;
6+
7+ use crate :: Cli ;
8+
9+ pub fn generate_manpages < P : AsRef < Path > > ( outdir : P ) -> Result < ( ) > {
10+ let outdir = outdir. as_ref ( ) ;
11+ std:: fs:: create_dir_all ( outdir) ?;
12+
13+ // Generate man page for main command
14+ let cmd = Cli :: command ( ) ;
15+ let mut out = File :: create ( outdir. join ( "spars.1" ) ) ?;
16+ Man :: new ( cmd. clone ( ) ) . render ( & mut out) ?;
17+
18+ // Generate man pages for subcommands
19+ for subcmd in cmd. get_subcommands ( ) {
20+ let mut out = File :: create ( outdir. join ( format ! ( "spars-{}.1" , subcmd. get_name( ) ) ) ) ?;
21+ Man :: new ( subcmd. clone ( ) ) . render ( & mut out) ?;
22+ }
23+
24+ Ok ( ( ) )
25+ }
You can’t perform that action at this time.
0 commit comments