Skip to content
Merged
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
11 changes: 8 additions & 3 deletions src/generators/man-page/utils/converter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ export function flagValueToMandoc(flag) {
}

// Split the flag into the name and value based on the separator ('=' or space).
const value = flag.split(sep)[1];
let value = flag.split(sep)[1];

// If the value ends with ']', the flag's argument is optional.
if (value.endsWith(']')) {
value = '[' + value;
}

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

// Combine prefix and formatted value.
return `${prefix} Ar ${value.replace(/\]$/, '')}`;
return `${prefix} Ar ${value}`;
}

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

/**
* Converts an API option metadata entry into the Mandoc format.
Expand Down
4 changes: 4 additions & 0 deletions src/test/man-page.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ describe('Mandoc Conversion', () => {
expected: ' Ns = Ns Ar value1,value2,value3',
},
{ input: '-x', expected: '' },
{
input: '--flag[=optional value]',
expected: ' Ns = Ns Ar [optional value]',
},
];
runTests(cases, flagValueToMandoc);
});
Expand Down
Loading