Repository: clap-rs/clap (language: rust)

Issue:
Styling issue about environment variables in generated man pages
### Please complete the following tasks

- [X] I have searched the [discussions](https://github.com/clap-rs/clap/discussions)
- [X] I have searched the [open](https://github.com/clap-rs/clap/issues) and [rejected](https://github.com/clap-rs/clap/issues?q=is%3Aissue+label%3AS-wont-fix+is%3Aclosed) issues

### Rust Version

rustc 1.59.0 (9d1b2106e 2022-02-23)

### Clap Version

master

### Minimal reproducible code

```rs
use clap::{arg, Command};
use clap_mangen::Man;
use std::io::{self, Result};

fn main() -> Result<()> {
    let cmd = Command::new("myapp").arg(
        arg!(-c --config <FILE> "Sets a custom config file")
            .long_help("Some more text about how to set a custom config file")
            .required(false)
            .takes_value(true)
            .default_value("config.toml")
            .env("CONFIG_FILE"),
    );

    Man::new(cmd).render(&mut io::stdout())
}
```

### Steps to reproduce the bug with the above code

`cargo run`

### Actual Behaviour

There is a missing space between argument and environment variable description.

```roff
.TP
\fB\-c\fR, \fB\-\-config\fR=\fIFILE\fR [default: config.toml]
Some more text about how to set a custom config fileMay also be specified with the \fBCONFIG_FILE\fR environment variable.
                                                  ^^^ a space/newline is needed here
```


<details>
<summary>Full output</summary>

```roff
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.TH myapp 1  "myapp "
.SH NAME
myapp
.SH SYNOPSIS
\fBmyapp\fR [\fB\-h\fR|\fB\-\-help\fR] [\fB\-c\fR|\fB\-\-config\fR]
.SH DESCRIPTION
.SH OPTIONS
.TP
\fB\-h\fR, \fB\-\-help\fR
Print help information
.TP
\fB\-c\fR, \fB\-\-config\fR=\fIFILE\fR [default: config.toml]
Some more text about how to set a custom config fileMay also be specified with the \fBCONFIG_FILE\fR environment variable.
```

</details>


### Expected Behaviour

```roff
.TP
\fB\-c\fR, \fB\-\-config\fR=\fIFILE\fR [default: config.toml]
Some more text about how to set a custom config file. May also be specified with the \fBCONFIG_FILE\fR environment variable. 
                                                    ^^^
```

### Additional Context

Same issue exists in the [clap_mangen example](https://github.com/clap-rs/clap/blob/e8010e79a994dcc31b3c753969cbe2022eaeb0d8/clap_mangen/examples/man.rs).

### Debug Output

\-


Discussion / hints:

Fix patch:
diff --git a/clap_mangen/src/render.rs b/clap_mangen/src/render.rs
index 49e15062a9c..b17f3bb849e 100644
--- a/clap_mangen/src/render.rs
+++ b/clap_mangen/src/render.rs
@@ -112,13 +112,15 @@ pub(crate) fn options(roff: &mut Roff, cmd: &clap::Command) {
             body.push(roman(help));
         }
 
-        if let Some(mut env) = option_environment(opt) {
-            body.append(&mut env);
-        }
-
         roff.control("TP", []);
         roff.text(header);
         roff.text(body);
+
+        if let Some(env) = option_environment(opt) {
+            roff.control("RS", []);
+            roff.text(env);
+            roff.control("RE", []);
+        }
     }
 
     for pos in items.iter().filter(|a| a.is_positional()) {
@@ -141,13 +143,15 @@ pub(crate) fn options(roff: &mut Roff, cmd: &clap::Command) {
             body.push(roman(&help.to_string()));
         }
 
-        if let Some(mut env) = option_environment(pos) {
-            body.append(&mut env);
-        }
-
         roff.control("TP", []);
         roff.text(header);
         roff.text(body);
+
+        if let Some(env) = option_environment(pos) {
+            roff.control("RS", []);
+            roff.text(env);
+            roff.control("RE", []);
+        }
     }
 }
 


Test patch:
diff --git a/clap_mangen/tests/common.rs b/clap_mangen/tests/common.rs
index 2ab5d932549..27a2e951cf6 100644
--- a/clap_mangen/tests/common.rs
+++ b/clap_mangen/tests/common.rs
@@ -231,6 +231,18 @@ pub fn hidden_option_command(name: &'static str) -> clap::Command<'static> {
         )
 }
 
+pub fn env_value_command(name: &'static str) -> clap::Command<'static> {
+    clap::Command::new(name).arg(
+        clap::Arg::new("config")
+            .short('c')
+            .long_help("Set configuration file path")
+            .required(false)
+            .takes_value(true)
+            .default_value("config.toml")
+            .env("CONFIG_FILE"),
+    )
+}
+
 pub fn assert_matches_path(expected_path: impl AsRef<std::path::Path>, cmd: clap::Command) {
     let mut buf = vec![];
     clap_mangen::Man::new(cmd).render(&mut buf).unwrap();
diff --git a/clap_mangen/tests/roff.rs b/clap_mangen/tests/roff.rs
index d48d070f409..946b8e764e5 100644
--- a/clap_mangen/tests/roff.rs
+++ b/clap_mangen/tests/roff.rs
@@ -55,3 +55,10 @@ fn hidden_options() {
     let cmd = common::hidden_option_command(name);
     common::assert_matches_path("tests/snapshots/hidden_option.bash.roff", cmd);
 }
+
+#[test]
+fn value_env() {
+    let name = "my-app";
+    let cmd = common::env_value_command(name);
+    common::assert_matches_path("tests/snapshots/value_env.bash.roff", cmd);
+}
diff --git a/clap_mangen/tests/snapshots/value_env.bash.roff b/clap_mangen/tests/snapshots/value_env.bash.roff
new file mode 100644
index 00000000000..4bed69f98c6
--- /dev/null
+++ b/clap_mangen/tests/snapshots/value_env.bash.roff
@@ -0,0 +1,18 @@
+.ie /n(.g .ds Aq /(aq
+.el .ds Aq '
+.TH my-app 1  "my-app " 
+.SH NAME
+my/-app
+.SH SYNOPSIS
+/fBmy/-app/fR [/fB/-h/fR|/fB/-/-help/fR] [/fB/-c /fR] 
+.SH DESCRIPTION
+.SH OPTIONS
+.TP
+/fB/-h/fR, /fB/-/-help/fR
+Print help information
+.TP
+/fB/-c/fR [default: config.toml]
+Set configuration file path
+.RS
+May also be specified with the /fBCONFIG_FILE/fR environment variable. 
+.RE