mirror of
https://github.com/rust-vmm/vhost-device.git
synced 2025-12-26 06:32:44 +00:00
xtask: generate manpage for vhost-device-scmi
Add vhost-device-scmi support for the mangen task in xtask binary.
This generates a manpage in target/dist/man/vhost-device-scmi.1
The rendered ROFF output looks like:
vhost-device-scmi(1) General Commands Manual vhost-device-scmi(1)
NAME
vhost-device-scmi - vhost-user SCMI backend device
SYNOPSIS
vhost-device-scmi <-s|--socket-path> [-d|--device] [--help-devices] [-h|--help] [-V|--version]
DESCRIPTION
vhost-user SCMI backend device
OPTIONS
-s, --socket-path=SOCKET_PATH
vhost-user socket to use
-d, --device=DEVICE
Devices to expose
--help-devices
Print help on available devices
-h, --help
Print help
-V, --version
Print version
VERSION
v0.3.0
REPORTING BUGS
Report bugs to the project's issue tracker: https://github.com/rust-vmm/vhost-device
vhost-device-scmi 0.3.0 vhost-device-scmi(1)
Fixes #697 ("Add man page for vhost-device-scmi")
Resolves: https://github.com/rust-vmm/vhost-device/issues/697
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
This commit is contained in:
parent
5624abb31f
commit
4ef66aae1e
@ -17,7 +17,8 @@ toml = { version = "0.8.19", optional = true }
|
||||
[build-dependencies]
|
||||
|
||||
[features]
|
||||
default = ["vhost-device-sound"]
|
||||
default = ["vhost-device-sound", "vhost-device-scmi"]
|
||||
vhost-device-scmi = []
|
||||
vhost-device-sound = ["vhost-device-sound-alsa", "vhost-device-sound-pipewire"]
|
||||
vhost-device-sound-alsa = ["mangen"]
|
||||
vhost-device-sound-pipewire = ["mangen"]
|
||||
|
||||
@ -26,6 +26,12 @@ use toml::value::Table;
|
||||
#[path = "../../vhost-device-sound/src/args.rs"]
|
||||
mod vhost_device_sound;
|
||||
|
||||
// Use vhost-device-scmi's args module as our own using the #[path] attribute
|
||||
|
||||
#[cfg(feature = "vhost-device-scmi")]
|
||||
#[path = "../../vhost-device-scmi/src/args.rs"]
|
||||
mod vhost_device_scmi;
|
||||
|
||||
fn main() {
|
||||
if let Err(err) = run_app() {
|
||||
eprintln!("{}", err);
|
||||
@ -56,6 +62,49 @@ fn print_help() {
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(feature = "mangen")]
|
||||
fn mangen_for_crate<T: CommandFactory>(manifest: Table) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||
let name: &'static str = manifest["package"]["name"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.leak();
|
||||
let version: &'static str = manifest["package"]["version"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.leak();
|
||||
let repository: &'static str = manifest["package"]["repository"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.leak();
|
||||
let description: &'static str = manifest["package"]["description"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.leak();
|
||||
let cmd = <T as CommandFactory>::command()
|
||||
.name(name)
|
||||
.display_name(name)
|
||||
.author(None)
|
||||
.bin_name(name)
|
||||
.version(version)
|
||||
.about(description);
|
||||
let man = Man::new(cmd);
|
||||
let mut buffer: Vec<u8> = Default::default();
|
||||
man.render(&mut buffer)?;
|
||||
clap_mangen::roff::Roff::new()
|
||||
.control("SH", ["REPORTING BUGS"])
|
||||
.text(vec![format!(
|
||||
"Report bugs to the project's issue tracker: {repository}"
|
||||
)
|
||||
.into()])
|
||||
.to_writer(&mut buffer)?;
|
||||
|
||||
Ok(buffer)
|
||||
}
|
||||
|
||||
#[cfg(feature = "mangen")]
|
||||
fn mangen() -> Result<(), Box<dyn Error>> {
|
||||
let workspace_dir = std::path::Path::new(&env!("CARGO_MANIFEST_DIR"))
|
||||
@ -67,8 +116,7 @@ fn mangen() -> Result<(), Box<dyn Error>> {
|
||||
let _ = std::fs::remove_dir_all(&dist_dir);
|
||||
std::fs::create_dir_all(&dist_dir)?;
|
||||
|
||||
let mut generated_artifacts = vec![];
|
||||
|
||||
let mut buffers = vec![];
|
||||
#[cfg(any(
|
||||
feature = "vhost-device-sound-pipewire",
|
||||
feature = "vhost-device-sound-alsa"
|
||||
@ -80,54 +128,38 @@ fn mangen() -> Result<(), Box<dyn Error>> {
|
||||
std::fs::read_to_string(workspace_dir.join("vhost-device-sound/Cargo.toml"))?;
|
||||
let manifest = manifest.as_str().parse::<Table>()?;
|
||||
|
||||
let name: &'static str = manifest["package"]["name"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.leak();
|
||||
let version: &'static str = manifest["package"]["version"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.leak();
|
||||
let repository: &'static str = manifest["package"]["repository"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.leak();
|
||||
let description: &'static str = manifest["package"]["description"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.leak();
|
||||
let cmd = <SoundArgs as CommandFactory>::command()
|
||||
.name(name)
|
||||
.display_name(name)
|
||||
.bin_name(name)
|
||||
.version(version)
|
||||
.about(description);
|
||||
let man = Man::new(cmd);
|
||||
let mut buffer: Vec<u8> = Default::default();
|
||||
man.render(&mut buffer)?;
|
||||
clap_mangen::roff::Roff::new()
|
||||
.control("SH", ["REPORTING BUGS"])
|
||||
.text(vec![format!(
|
||||
"Report bugs to the project's issue tracker: {repository}"
|
||||
)
|
||||
.into()])
|
||||
.to_writer(&mut buffer)?;
|
||||
|
||||
let buffer = mangen_for_crate::<SoundArgs>(manifest)?;
|
||||
let man_path = dist_dir.join("vhost-device-sound.1");
|
||||
buffers.push((man_path, buffer));
|
||||
}
|
||||
#[cfg(feature = "vhost-device-scmi")]
|
||||
{
|
||||
use vhost_device_scmi::ScmiArgs;
|
||||
|
||||
let manifest = std::fs::read_to_string(workspace_dir.join("vhost-device-scmi/Cargo.toml"))?;
|
||||
let manifest = manifest.as_str().parse::<Table>()?;
|
||||
|
||||
let buffer = mangen_for_crate::<ScmiArgs>(manifest)?;
|
||||
let man_path = dist_dir.join("vhost-device-scmi.1");
|
||||
buffers.push((man_path, buffer));
|
||||
}
|
||||
|
||||
if buffers.is_empty() {
|
||||
println!("No manpages were generated! Try using the correct xtask cargo features.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut generated_artifacts = Vec::with_capacity(buffers.len());
|
||||
|
||||
for (man_path, buffer) in buffers {
|
||||
std::fs::write(&man_path, buffer)?;
|
||||
generated_artifacts.push(man_path);
|
||||
}
|
||||
if generated_artifacts.is_empty() {
|
||||
println!("No manpages were generated! Try using the correct xtask cargo features.");
|
||||
} else {
|
||||
println!("Generated the following manual pages:");
|
||||
for art in generated_artifacts {
|
||||
println!("{}", art.display());
|
||||
}
|
||||
|
||||
assert!(!generated_artifacts.is_empty());
|
||||
println!("Generated the following manual pages:");
|
||||
for art in generated_artifacts {
|
||||
println!("{}", art.display());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user