Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add manpages feature needed to build the manual #17

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ jobs:
-Z build-std=std,panic_abort \
-Z build-std-features=optimize_for_size,panic_immediate_abort \
--target ${{ steps.get-rust-target.outputs.target }} \
--release
--release \
--features=manpages
- name: Standarize Windows executable path
if: matrix.runs-on == 'windows-latest'
shell: bash
Expand Down Expand Up @@ -178,7 +179,7 @@ jobs:
target
key: ${{ runner.os }}-cargo-unit-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }}
- name: Run unit tests
run: cargo test
run: cargo test --all-features

test-release:
needs:
Expand All @@ -201,7 +202,7 @@ jobs:
- name: Publish
run: |
cargo login ${{ secrets.CRATES_TOKEN }}
cargo publish -v --dry-run
cargo publish -v --dry-run --features=manpages

release:
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -218,7 +219,7 @@ jobs:
- name: Publish
run: |
cargo login ${{ secrets.CRATES_TOKEN }}
cargo publish -v
cargo publish -v --features=manpages

create-release:
if: startsWith(github.ref, 'refs/tags/')
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Changes

- Add MSRV.
- Add `manpages` feature to build MAN pages (`clap_mangen` not used by default).

## 2025-01-14 - [0.2.3]

Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ anstyle = { version = "1", optional = true, default-features = false }
default = ["color", "auto-color"]
color = ["dep:anstream", "dep:anstyle", "clap/color"]
auto-color = ["anstream?/auto", "anstream?/wincon"]
manpages = ["dep:clap_mangen"]

[profile.release]
strip = true
Expand All @@ -50,7 +51,7 @@ clap = { version = "4", default-features = false, features = ["std", "help"] }

[build-dependencies]
clap.workspace = true
clap_mangen = "0.2"
clap_mangen = { version = ">=0.2", optional = true }

[package.metadata.binstall]
pkg-url = "{ repo }/releases/download/v{ version }/{ name }-{ target }{ archive-suffix }"
51 changes: 24 additions & 27 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
use clap_mangen::Man;
use std::{
env,
fs::File,
io::Error,
path::{Path, PathBuf},
};

#[cfg(feature = "manpages")]
include!("src/cli.rs");

fn build_manpages(outdir: &Path) -> Result<(), Error> {
#[cfg(feature = "manpages")]
fn build_manpages(outdir: &std::path::Path) -> Result<(), std::io::Error> {
let app = cli();

let file = Path::new(&outdir).join("example.1");
let mut file = File::create(&file)?;
let file = std::path::Path::new(&outdir).join("example.1");
let mut file = std::fs::File::create(&file)?;

Man::new(app).render(&mut file)?;
clap_mangen::Man::new(app).render(&mut file)?;

Ok(())
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=src/cli.rs");
println!("cargo:rerun-if-changed=man");

let outdir = match env::var_os("OUT_DIR") {
None => return Ok(()),
Some(outdir) => outdir,
};

// Create `target/assets/` folder.
let out_path = PathBuf::from(outdir);
let mut path = out_path.ancestors().nth(4).unwrap().to_owned();
path.push("assets");
std::fs::create_dir_all(&path).unwrap();

build_manpages(&path)?;
#[cfg(feature = "manpages")]
{
println!("cargo:rerun-if-changed=src/cli.rs");
println!("cargo:rerun-if-changed=man");

let outdir = match std::env::var_os("OUT_DIR") {
None => return Ok(()),
Some(outdir) => outdir,
};

// Create `target/assets/` folder.
let out_path = std::path::PathBuf::from(outdir);
let mut path = out_path.ancestors().nth(4).unwrap().to_owned();
path.push("assets");
std::fs::create_dir_all(&path).unwrap();

build_manpages(&path)?;
}

Ok(())
}
Loading