Skip to content

Commit 8b7a3d6

Browse files
committed
fix(man-page): account for optional flag arguments
1 parent 7f2c125 commit 8b7a3d6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/generators/man-page/utils/converter.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ export function flagValueToMandoc(flag) {
7878
}
7979

8080
// Split the flag into the name and value based on the separator ('=' or space).
81-
const value = flag.split(sep)[1];
81+
let value = flag.split(sep)[1];
82+
83+
// If the value ends with ']', the flag's argument is optional.
84+
if (value.endsWith(']')) {
85+
value = '[' + value;
86+
}
8287

8388
// If there is no value, return an empty string.
8489
if (!value) {
@@ -89,12 +94,12 @@ export function flagValueToMandoc(flag) {
8994
const prefix = sep === ' ' ? '' : ' Ns = Ns';
9095

9196
// Combine prefix and formatted value.
92-
return `${prefix} Ar ${value.replace(/\]$/, '')}`;
97+
return `${prefix} Ar ${value}`;
9398
}
9499

95100
const formatFlag = flag =>
96101
// 'Fl' denotes a flag, followed by an optional 'Ar' (argument).
97-
`Fl ${flag.split(/[= ]/)[0].slice(1)}${flagValueToMandoc(flag)}`;
102+
`Fl ${flag.split(/\[?[= ]/)[0].slice(1)}${flagValueToMandoc(flag)}`;
98103

99104
/**
100105
* Converts an API option metadata entry into the Mandoc format.

0 commit comments

Comments
 (0)