Skip to content

Commit

Permalink
automatically update the markdown command line help
Browse files Browse the repository at this point in the history
  • Loading branch information
glehmann committed Feb 3, 2024
1 parent 73939b5 commit 23aecbf
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 8 deletions.
23 changes: 20 additions & 3 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 @@ -34,6 +34,7 @@ clap = { version = "4.4.18", features = ["derive", "env", "wrap_help"] }
clap-markdown = "0.1.3"
clap-verbosity-flag = "2.1.2"
clap_mangen = "0.2.18"
clap_complete = "4.4.10"

[profile.release]
strip = "symbols"
Expand Down
13 changes: 11 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use std::{fs, io::Write};

include!("src/cli.rs");

fn main() -> std::io::Result<()> {
generate_man::<Cli>()?;
generate_markdown::<Cli>()?;
Ok(())
}

fn generate_man<C: clap::CommandFactory>() -> std::io::Result<()> {
let command = C::command();
let out_dir =
std::path::PathBuf::from(std::env::var_os("OUT_DIR").ok_or(std::io::ErrorKind::NotFound)?);
let out_dir: PathBuf = "docs".into();
let name = command.get_name();
let name = if name == "yage" {
"yage.1".to_owned()
Expand All @@ -22,3 +24,10 @@ fn generate_man<C: clap::CommandFactory>() -> std::io::Result<()> {
std::fs::write(fname, buffer)?;
Ok(())
}

fn generate_markdown<C: clap::CommandFactory>() -> std::io::Result<()> {
let md = clap_markdown::help_markdown::<Cli>();
let mut f = fs::File::create("docs/CommandLineHelp.md")?;
write!(f, "{md}")?;
Ok(())
}
5 changes: 2 additions & 3 deletions docs/CommandLineHelp.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ This document contains the help content for the `yage` command-line program.

## `yage`

A simple tool to manage encrypted secrets in YAML files.
A simple tool to manage encrypted secrets in YAML files with age encryption

**Usage:** `yage [OPTIONS] [COMMAND]`
**Usage:** `yage [OPTIONS] <COMMAND>`

###### **Subcommands:**

Expand Down Expand Up @@ -194,4 +194,3 @@ The input key and output public key are in the age format, which is compatible w
This document was generated automatically by
<a href="https://crates.io/crates/clap-markdown"><code>clap-markdown</code></a>.
</i></small>

55 changes: 55 additions & 0 deletions docs/yage.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.TH yage 1 "yage 0.1.0"
.SH NAME
yage \- A simple tool to manage encrypted secrets in YAML files with age encryption
.SH SYNOPSIS
\fByage\fR [\fB\-\-completion\fR] [\fB\-v\fR|\fB\-\-verbose\fR]... [\fB\-q\fR|\fB\-\-quiet\fR]... [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] <\fIsubcommands\fR>
.SH DESCRIPTION
A simple tool to manage encrypted secrets in YAML files with age encryption
.SH OPTIONS
.TP
\fB\-\-completion\fR=\fISHELL\fR
Generate the completion code for this shell
.br

.br
[\fIpossible values: \fRbash, elvish, fish, powershell, zsh]
.TP
\fB\-v\fR, \fB\-\-verbose\fR
Increase logging verbosity
.TP
\fB\-q\fR, \fB\-\-quiet\fR
Decrease logging verbosity
.TP
\fB\-h\fR, \fB\-\-help\fR
Print help
.TP
\fB\-V\fR, \fB\-\-version\fR
Print version
.SH SUBCOMMANDS
.TP
yage\-decrypt(1)
Decrypt the values in a YAML file
.TP
yage\-edit(1)
Edit an encrypted YAML file
.TP
yage\-encrypt(1)
Encrypt the values in a YAML file
.TP
yage\-env(1)
Execute a command with the environment from the encrypted YAML file
.TP
yage\-keygen(1)
Generate a new age key
.TP
yage\-pubkey(1)
Convert private age keys to their public key
.TP
yage\-help(1)
Print this message or the help of the given subcommand(s)
.SH VERSION
v0.1.0
.SH AUTHORS
Gaëtan Lehmann <gaetan.lehmann@gmail.com>

0 comments on commit 23aecbf

Please sign in to comment.