diff --git a/impl/command_line/options.cxx b/impl/command_line/options.cxx index 8a6ec95c..27733520 100644 --- a/impl/command_line/options.cxx +++ b/impl/command_line/options.cxx @@ -184,28 +184,58 @@ namespace substrate::commandLine }, _option); } + [[nodiscard]] inline std::string_view option_t::typeToValue() const noexcept + { + switch (_valueType){ + case optionValueType_t::signedInt: + return "INT"sv; + case optionValueType_t::unsignedInt: + return "UINT"sv; + case optionValueType_t::boolean: + return "BOOL"sv; + case optionValueType_t::string: + return "STRING"sv; + case optionValueType_t::path: + return "PATH"sv; + case optionValueType_t::userDefined: + return "VAL"sv; + } + } + [[nodiscard]] std::string option_t::displayName() const noexcept { if (_option.valueless_by_exception()) return ""s; + const auto typeValue = [&]() -> std::string { + if (!takesParameter()) + return {}; + return " "s + std::string{typeToValue()}; + }(); return std::visit(match_t { - [](const std::string_view &option) { return std::string{option}; }, - [](const optionFlagPair_t &option) - { return std::string{option._shortFlag} + ", "s + std::string{option._longFlag}; }, - [](const optionValue_t &option) { return std::string{option.metaName()}; }, + [&typeValue](const std::string_view &option) { return std::string{option} + typeValue ; }, + [&typeValue](const optionFlagPair_t &option) + { + return std::string{option._shortFlag} + ", "s + std::string{option._longFlag} + typeValue; + }, + [this](const optionValue_t &option) { return std::string{option.metaName()} + (isRepeatable() ? "..."s : ""s); } }, _option); } [[nodiscard]] size_t option_t::displayLength() const noexcept { + const auto value_length{[&]() -> size_t { + if (!takesParameter()) + return 0U; + return typeToValue().length() + 1U; + }()}; return std::visit(match_t { - [](const std::string_view &option) { return option.length(); }, - [](const optionFlagPair_t &option) + [&value_length](const std::string_view &option) { return option.length() + value_length; }, + [&value_length](const optionFlagPair_t &option) // Add the lengths of the two flags together, and the extra ", " that is inserted by displayName() - { return option._shortFlag.length() + option._longFlag.length() + 2U; }, - [](const optionValue_t &option) { return option.metaName().length(); }, + { return option._shortFlag.length() + option._longFlag.length() + 2U + value_length; }, + [this](const optionValue_t &option) { return option.metaName().length() + (isRepeatable() ? 3U : 0U); }, }, _option); } diff --git a/substrate/command_line/options b/substrate/command_line/options index d02bce1d..6e92f659 100644 --- a/substrate/command_line/options +++ b/substrate/command_line/options @@ -175,6 +175,7 @@ namespace substrate::commandLine } private: + [[nodiscard]] std::string_view typeToValue() const noexcept; [[nodiscard]] std::optional parseSignedValue(const std::string_view &value) const noexcept; [[nodiscard]] std::optional parseUnsignedValue(const std::string_view &value) const noexcept; [[nodiscard]] static std::optional parseBoolValue(const std::string_view &value) noexcept;