Skip to content

Commit

Permalink
command_line/options: Implemented optionSet_t::displayHelp() with sup…
Browse files Browse the repository at this point in the history
…port for optional padding
  • Loading branch information
dragonmux committed Aug 15, 2023
1 parent 0cc6167 commit fc997ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions impl/command_line/options.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ namespace substrate::commandLine
);
}

void optionSet_t::displayHelp(const size_t padding) const noexcept
{
console.writeln();
// XXX: Need to capitalise the first letter.
console.writeln(metaName(), "s:"sv);
for (const auto &alternation : _alternations)
{
console.writeln('\t', alternation.displayName(), nullptr);
for ([[maybe_unused]] const auto _ : substrate::indexSequence_t{alternation.displayLength(), padding})
console.writeln(' ', nullptr);
console.writeln(' ', alternation.helpText());
}
}

// Implementation of the innards of optionSet_t as otherwise we get compile errors
const optionAlternation_t *optionSet_t::begin() const noexcept
{ return _alternations.begin(); }
Expand Down
3 changes: 2 additions & 1 deletion substrate/command_line/options
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ namespace substrate::commandLine

[[nodiscard]] bool matches(const std::string_view &argument) const noexcept;
[[nodiscard]] std::optional<std::any> parseValue(const std::string_view &value) const noexcept;
void displayHelp(size_t padding = 0U) const noexcept;

[[nodiscard]] constexpr bool takesParameter() const noexcept
{ return _flags.includes(optionFlags_t::takesParameter); }
Expand All @@ -151,6 +150,7 @@ namespace substrate::commandLine
[[nodiscard]] std::string_view metaName() const noexcept;
[[nodiscard]] std::string displayName() const noexcept;
[[nodiscard]] size_t displayLength() const noexcept;
void displayHelp(size_t padding = 0U) const noexcept;
[[nodiscard]] constexpr auto &helpText() const noexcept { return _help; }

[[nodiscard]] constexpr bool operator <(const option_t &other) const noexcept
Expand Down Expand Up @@ -202,6 +202,7 @@ namespace substrate::commandLine
[[nodiscard]] std::optional<std::reference_wrapper<const optionAlternation_t>>
matches(const std::string_view &argument) const noexcept;
[[nodiscard]] size_t displayPadding() const noexcept;
void displayHelp(size_t padding = 0U) const noexcept;

[[nodiscard]] const optionAlternation_t *begin() const noexcept;
[[nodiscard]] const optionAlternation_t *end() const noexcept;
Expand Down

0 comments on commit fc997ac

Please sign in to comment.