Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,23 @@ fn write_help_markdown(
title_name
).unwrap();

//----------------------------------
// Write the version if available
//----------------------------------

if let Some(version) = command.get_version() {
let version_str = version.to_string();

// Check if version contains multiple lines
if version_str.contains('\n') {
// Multi-line version: use a code block
writeln!(buffer, "**Version:**\n\n```\n{}\n```\n", version_str.trim()).unwrap();
} else {
// Single-line version: use inline code
writeln!(buffer, "**Version:** `{}`\n", version_str).unwrap();
}
}

//----------------------------------
// Write the table of contents
//----------------------------------
Expand Down
55 changes: 55 additions & 0 deletions tests/test_markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Options:

This document contains the help content for the `my-program-display-name` command-line program.

**Version:** `1.2.3`

**Command Overview:**

* [`my-program-display-name`↴](#my-program-display-name)
Expand Down Expand Up @@ -133,6 +135,8 @@ Options:

This document contains the help content for the `my-program-display-name` command-line program.

**Version:** `1.2.3`

**Command Overview:**

* [`my-program-display-name`↴](#my-program-display-name)
Expand All @@ -151,6 +155,57 @@ This program does things.



"
);
}

/// Test behavior for an app with a multi-line version string
#[test]
fn test_version_behavior_for_multi_line_version_string() {
let multi_line_version = "my-cli 1.2.3 (abc123def)\nmy-lib 2.0.0 (789xyz456)\ndependency 3.1.0 (fedcba987)";

let mut app = Command::new("my-cli")
.version(multi_line_version)
.about("A CLI tool with multiple component versions")
.arg(Arg::new("input").short('i'));
let () = app.build();

assert_eq!(
help_markdown_command_custom(
&app,
&MarkdownOptions::new().show_footer(false)
),
"\
# Command-Line Help for `my-cli`

This document contains the help content for the `my-cli` command-line program.

**Version:**

```
my-cli 1.2.3 (abc123def)
my-lib 2.0.0 (789xyz456)
dependency 3.1.0 (fedcba987)
```

**Command Overview:**

* [`my-cli`↴](#my-cli)

## `my-cli`

A CLI tool with multiple component versions

**Usage:** `my-cli [OPTIONS]`

###### **Options:**

* `-i <INPUT>`
* `-h`, `--help` — Print help
* `-V`, `--version` — Print version



"
);
}