Skip to content

Commit 24ec093

Browse files
committed
Add man pages
1 parent 65186a1 commit 24ec093

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ readme = "README.md"
1111
[dependencies]
1212
clap = { version = "4.0", features = ["derive"] }
1313
flate2 = "1.0"
14-
regex = "1.5"
14+
regex = "1.5"
15+
clap_mangen = "0.2"

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,33 @@ cd spars; cargo install --path .
3636
```
3737

3838
Precompiled 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+
```

src/main.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use clap::{Parser, Subcommand, ArgGroup};
22
use std::error::Error;
3-
3+
use std::path::PathBuf;
44
mod stats;
55
mod subset;
66
mod 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

7085
fn 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(())

src/man.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

0 commit comments

Comments
 (0)