Skip to content

Commit

Permalink
Merge pull request #1319 from cachix/generate-manpages
Browse files Browse the repository at this point in the history
devenv: generate and ship manpages
  • Loading branch information
domenkozar authored Jul 5, 2024
2 parents 2e6c99c + f263bde commit 7b3ed61
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
xtask = "run --package xtask --"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ result
.direnv*
/.cache
/.pre-commit-config.yaml
man

# examples
examples/rust/app/target
Expand Down
35 changes: 31 additions & 4 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"
members = [
"devenv",
"devenv-run-tests",
"xtask",
]

[workspace.package]
Expand Down
3 changes: 1 addition & 2 deletions devenv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ miette.workspace = true
nix.workspace = true
regex.workspace = true
reqwest.workspace = true
schemars.workspace = true
schematic.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand All @@ -28,5 +29,3 @@ tracing.workspace = true
which.workspace = true
whoami.workspace = true
xdg.workspace = true

schemars.workspace = true
1 change: 1 addition & 0 deletions devenv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::PathBuf;

#[derive(Parser)]
#[command(
name = "devenv",
color = clap::ColorChoice::Auto,
// for --clean to work with subcommands
subcommand_precedence_over_arg = true,
Expand Down
31 changes: 24 additions & 7 deletions package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,42 @@ pkgs.rustPlatform.buildRustPackage {
version = "1.0.7";

src = pkgs.lib.sourceByRegex ./. [
"Cargo.toml"
"Cargo.lock"
"devenv(/\.*)?"
"devenv-run-tests(/\.*)?"
"^\.cargo(/.*)?$"
"Cargo\.toml"
"Cargo\.lock"
"devenv(/.*)?"
"devenv-run-tests(/.*)?"
"xtask(/.*)?"
];

cargoBuildFlags = [ "-p devenv -p devenv-run-tests" ];

cargoLock = {
lockFile = ./Cargo.lock;
};

nativeBuildInputs = [ pkgs.makeWrapper pkgs.pkg-config ];
nativeBuildInputs = [
pkgs.makeWrapper
pkgs.pkg-config
pkgs.installShellFiles
];

buildInputs = [ pkgs.openssl ] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
];

postInstall = ''
wrapProgram $out/bin/devenv --set DEVENV_NIX ${inputs.nix.packages.${pkgs.stdenv.system}.nix} --prefix PATH ":" "$out/bin:${inputs.cachix.packages.${pkgs.stdenv.system}.cachix}/bin"
wrapProgram $out/bin/devenv \
--set DEVENV_NIX ${inputs.nix.packages.${pkgs.stdenv.system}.nix} \
--prefix PATH ":" "$out/bin:${inputs.cachix.packages.${pkgs.stdenv.system}.cachix}/bin"
# TODO: problematic for our library...
wrapProgram $out/bin/devenv-run-tests --set DEVENV_NIX ${inputs.nix.packages.${pkgs.stdenv.system}.nix} --prefix PATH ":" "$out/bin:${inputs.cachix.packages.${pkgs.stdenv.system}.cachix}/bin"
wrapProgram $out/bin/devenv-run-tests \
--set DEVENV_NIX ${inputs.nix.packages.${pkgs.stdenv.system}.nix} \
--prefix PATH ":" "$out/bin:${inputs.cachix.packages.${pkgs.stdenv.system}.cachix}/bin"
# Generate manpages
cargo xtask generate-manpages --out-dir man
installManPage man/*
'';
}
10 changes: 10 additions & 0 deletions xtask/Cargo.toml
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
31 changes: 31 additions & 0 deletions xtask/src/main.rs
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),
}
}
19 changes: 19 additions & 0 deletions xtask/src/manpage.rs
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")
}

0 comments on commit 7b3ed61

Please sign in to comment.