-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1319 from cachix/generate-manpages
devenv: generate and ship manpages
- Loading branch information
Showing
10 changed files
with
121 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[alias] | ||
xtask = "run --package xtask --" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ result | |
.direnv* | ||
/.cache | ||
/.pre-commit-config.yaml | ||
man | ||
|
||
# examples | ||
examples/rust/app/target | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ resolver = "2" | |
members = [ | ||
"devenv", | ||
"devenv-run-tests", | ||
"xtask", | ||
] | ||
|
||
[workspace.package] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "xtask" | ||
version = "0.1.0" | ||
edition.workspace = true | ||
|
||
[dependencies] | ||
clap.workspace = true | ||
clap_mangen = "0.2.22" | ||
devenv = { path = "../devenv" } | ||
miette.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use clap::Parser; | ||
use miette::Result; | ||
|
||
mod manpage; | ||
|
||
#[derive(clap::Parser)] | ||
struct Cli { | ||
#[command(subcommand)] | ||
pub(crate) command: Command, | ||
} | ||
|
||
#[derive(clap::Subcommand)] | ||
enum Command { | ||
GenerateManpages { | ||
#[clap( | ||
long, | ||
value_parser, | ||
value_hint = clap::ValueHint::DirPath, | ||
default_value_os_t = manpage::default_out_dir() | ||
)] | ||
out_dir: std::path::PathBuf, | ||
}, | ||
} | ||
|
||
fn main() -> Result<()> { | ||
let cli = Cli::parse(); | ||
|
||
match cli.command { | ||
Command::GenerateManpages { out_dir } => manpage::generate_manpages(out_dir), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use clap::CommandFactory; | ||
use miette::{IntoDiagnostic, Result}; | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
|
||
mod cli { | ||
include!("../../devenv/src/cli.rs"); | ||
} | ||
|
||
pub fn generate_manpages(out_dir: impl AsRef<Path>) -> Result<()> { | ||
fs::create_dir_all(&out_dir).into_diagnostic()?; | ||
clap_mangen::generate_to(cli::Cli::command(), &out_dir).into_diagnostic()?; | ||
println!("Generated man pages to {}", out_dir.as_ref().display()); | ||
Ok(()) | ||
} | ||
|
||
pub fn default_out_dir() -> PathBuf { | ||
std::env::current_dir().unwrap().join("man") | ||
} |