Skip to content

Commit

Permalink
gen-manpage: fixes and simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxVerevkin committed Jun 19, 2022
1 parent eb22f91 commit 97d3e0d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 202 deletions.
93 changes: 0 additions & 93 deletions gen-manpage/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions gen-manpage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@
name = "gen-manpage"
version = "0.1.0"
edition = "2021"

[dependencies]
tempfile = "3.3"
34 changes: 7 additions & 27 deletions gen-manpage/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ use std::env::args;
use std::fs::{read_dir, File};
use std::io::{BufRead, BufReader, Result, Write};
use std::path::PathBuf;
use std::process::{exit, Command};
use tempfile::NamedTempFile;
use std::process::exit;

const USAGE: &str = concat!(
"i3status-rust manpage generator\n",
"\n",
"USAGE:\n",
" gen-manpage <i3status-rs str dir> <output dir>\n",
" gen-manpage <i3status-rs str dir> <output file>\n",
"EXAMPLE:\n",
" gen-manpage ../src/blocks ../man\n",
" gen-manpage ../src/blocks ../man/blocks.md\n",
);

fn main() {
Expand All @@ -24,7 +23,7 @@ fn main() {
exit(1);
}
};
let out_dir = match args.next() {
let out_path = match args.next() {
Some(p) => PathBuf::from(p),
None => {
eprintln!("{USAGE}");
Expand Down Expand Up @@ -63,7 +62,7 @@ fn main() {
line = &line[1..];
}

if line.starts_with("#") {
if line.starts_with('#') {
doc.push_str("##")
}
doc.push_str(line);
Expand All @@ -77,27 +76,8 @@ fn main() {

result.sort_unstable_by(|a, b| a.0.cmp(&b.0));

let mut markdown = NamedTempFile::new().unwrap();
for (block, _) in &result {
writeln!(markdown, "- [{block}]({block})").unwrap();
}
let mut markdown = File::create(out_path).unwrap();
for (block, doc) in &result {
writeln!(markdown, "- ## {block}\n{doc}").unwrap();
writeln!(markdown, "## {block}\n{doc}").unwrap();
}
markdown.flush().unwrap();

Command::new("pandoc")
.arg("-o")
.arg(out_dir.join("blocks.1"))
.arg("-f")
.arg("markdown")
.arg("-t")
.arg("man")
.arg(markdown.path())
.spawn()
.unwrap()
.wait()
.unwrap();

drop(markdown);
}
8 changes: 3 additions & 5 deletions man/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ else
OUT=$1
fi

(cd gen-manpage && cargo run -- ../src ../man)
(cd gen-manpage && cargo run -- ../src ../man/blocks.md)

pandoc -o man/blocks.1 -t man man/blocks.md
# TODO: fix deprecation warning
pandoc -o man/themes.1 -t man --base-header-level=2 doc/themes.md

# Delete the table of contents from the block documentation.
sed -i '0,/xrandr/d' man/blocks.1

# Add appropriate section headers.
sed -i '1i .SH BLOCKS\n' man/blocks.1
sed -i '1i .SH THEMES\n' man/themes.1

# Stich together the final manpage.
cat man/_preface.1 man/blocks.1 man/themes.1 man/_postface.1 > $OUT

rm man/blocks.1 man/themes.1
rm man/blocks.md man/blocks.1 man/themes.1
Loading

0 comments on commit 97d3e0d

Please sign in to comment.