Skip to content

Commit

Permalink
iox-eclipse-iceoryx#846 Remove OPTIONAL from windows platform correction
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Jan 8, 2025
1 parent 72e942e commit 795d5de
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion iceoryx_hoofs/cli/include/iox/cli/option.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct OptionWithDetails : public Option // can this be melt together
struct
{
OptionDescription_t description;
OptionType type = OptionType::SWITCH;
OptionType type = OptionType::Switch;
TypeName_t typeName;
} details;
};
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/cli/include/iox/cli/option_manager.inl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ inline bool OptionManager::extractOptionArgumentValue(const Arguments& arguments
const OptionName_t& name,
const OptionType optionType)
{
if (optionType == OptionType::SWITCH)
if (optionType == OptionType::Switch)
{
return arguments.isSwitchSet(getLookupName(shortName, name));
}
Expand Down
6 changes: 3 additions & 3 deletions iceoryx_hoofs/cli/include/iox/cli/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ namespace cli
enum class OptionType : uint8_t
{
/// @brief option when provided is true
SWITCH,
Switch,
/// @brief option with value which has to be provided
REQUIRED,
Required,
/// @brief option with value which can be provided
OPTIONAL
Optional
};

static constexpr uint64_t MAX_OPTION_NAME_LENGTH = 32;
Expand Down
6 changes: 3 additions & 3 deletions iceoryx_hoofs/cli/include/iox/cli_definition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
/// @param[in] description a description of the optional value
#define IOX_CLI_OPTIONAL(type, memberName, defaultValue, shortName, longName, description) \
IOX_INTERNAL_CMD_LINE_VALUE( \
type, memberName, defaultValue, shortName, longName, description, iox::cli::OptionType::OPTIONAL)
type, memberName, defaultValue, shortName, longName, description, iox::cli::OptionType::Optional)

/// @brief Adds a required value to the command line, if it is not provided the program will print the help and
/// terminate
Expand All @@ -57,15 +57,15 @@
/// @param[in] description a description of the required value
#define IOX_CLI_REQUIRED(type, memberName, shortName, longName, description) \
IOX_INTERNAL_CMD_LINE_VALUE( \
type, memberName, type(), shortName, longName, description, iox::cli::OptionType::REQUIRED)
type, memberName, type(), shortName, longName, description, iox::cli::OptionType::Required)

/// @brief Adds a switch to the command line
/// @param[in] memberName the name under which the switch is accessible
/// @param[in] shortName a single character for the short option like '-s' for instance
/// @param[in] longName a long option name under which this can be accessed like '--some-name' for instance
/// @param[in] description a description of the switch
#define IOX_CLI_SWITCH(memberName, shortName, longName, description) \
IOX_INTERNAL_CMD_LINE_VALUE(bool, memberName, false, shortName, longName, description, iox::cli::OptionType::SWITCH)
IOX_INTERNAL_CMD_LINE_VALUE(bool, memberName, false, shortName, longName, description, iox::cli::OptionType::Switch)

/// @brief Helper macro to create a struct with full command line parsing from argc, argv.
/// @param[in] Name the name of the class/struct
Expand Down
10 changes: 5 additions & 5 deletions iceoryx_hoofs/cli/source/command_line_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ CommandLineParser::parse(const OptionDefinition& optionSet, int argc, char** arg
return m_optionValue;
}

if (optionEntry->details.type == OptionType::SWITCH)
if (optionEntry->details.type == OptionType::Switch)
{
m_optionValue.m_arguments.emplace_back(*optionEntry);
m_optionValue.m_arguments.back().value.clear();
Expand Down Expand Up @@ -271,7 +271,7 @@ void CommandLineParser::setDefaultValuesToUnsetOptions() noexcept // rename
{
for (const auto& availableOption : m_optionSet->m_availableOptions)
{
if (availableOption.details.type != OptionType::OPTIONAL)
if (availableOption.details.type != OptionType::Optional)
{
continue;
}
Expand All @@ -298,7 +298,7 @@ bool CommandLineParser::areAllRequiredValuesPresent() const noexcept
bool areAllRequiredValuesPresent = true;
for (const auto& availableOption : m_optionSet->m_availableOptions)
{
if (availableOption.details.type == OptionType::REQUIRED)
if (availableOption.details.type == OptionType::Required)
{
bool isValuePresent = false;
for (const auto& option : m_optionValue.m_arguments)
Expand Down Expand Up @@ -359,7 +359,7 @@ void CommandLineParser::printHelpAndExit() const noexcept
outLength += 2 + option.longOption.size();
}

if (option.details.type == OptionType::REQUIRED || option.details.type == OptionType::OPTIONAL)
if (option.details.type == OptionType::Required || option.details.type == OptionType::Optional)
{
std::cout << " [" << option.details.typeName << "]";
outLength += 3 + option.details.typeName.size();
Expand All @@ -373,7 +373,7 @@ void CommandLineParser::printHelpAndExit() const noexcept
}
std::cout << option.details.description << std::endl;

if (option.details.type == OptionType::OPTIONAL)
if (option.details.type == OptionType::Optional)
{
for (uint64_t i = 0; i < OPTION_OUTPUT_WIDTH; ++i)
{
Expand Down
8 changes: 4 additions & 4 deletions iceoryx_hoofs/cli/source/option_definition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ OptionDefinition::OptionDefinition(const OptionDescription_t& programDescription
, m_onFailureCallback{onFailureCallback}
{
constexpr bool IS_SWITCH = true;
std::move(*this).addOption({{'h', IS_SWITCH, {"help"}, {""}}, {"Display help."}, OptionType::SWITCH, {""}});
std::move(*this).addOption({{'h', IS_SWITCH, {"help"}, {""}}, {"Display help."}, OptionType::Switch, {""}});
}

optional<OptionWithDetails> OptionDefinition::getOption(const OptionName_t& name) const noexcept
Expand Down Expand Up @@ -100,7 +100,7 @@ OptionDefinition& OptionDefinition::addSwitch(const char shortOption,
const OptionDescription_t& description) noexcept
{
constexpr bool IS_SWITCH = true;
return addOption({{shortOption, IS_SWITCH, longOption, {""}}, description, OptionType::SWITCH, {""}});
return addOption({{shortOption, IS_SWITCH, longOption, {""}}, description, OptionType::Switch, {""}});
}

// NOLINTJUSTIFICATION this is not a user facing API but hidden in a macro
Expand All @@ -113,15 +113,15 @@ OptionDefinition& OptionDefinition::addOptional(const char shortOption,
{
constexpr bool IS_NO_SWITCH = false;
return addOption(
{{shortOption, IS_NO_SWITCH, longOption, defaultValue}, description, OptionType::OPTIONAL, typeName});
{{shortOption, IS_NO_SWITCH, longOption, defaultValue}, description, OptionType::Optional, typeName});
}
OptionDefinition& OptionDefinition::addRequired(const char shortOption,
const OptionName_t& longOption,
const OptionDescription_t& description,
const TypeName_t& typeName) noexcept
{
constexpr bool IS_NO_SWITCH = false;
return addOption({{shortOption, IS_NO_SWITCH, longOption, {""}}, description, OptionType::REQUIRED, typeName});
return addOption({{shortOption, IS_NO_SWITCH, longOption, {""}}, description, OptionType::Required, typeName});
}

std::ostream& operator<<(std::ostream& stream, const OptionWithDetails& option) noexcept
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/test/moduletests/test_cli_option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct OptionWithDetailsFactory
using Type_t = OptionWithDetails;
static Type_t createEmpty()
{
return Type_t{{}, "", iox::cli::OptionType::SWITCH, ""};
return Type_t{{}, "", iox::cli::OptionType::Switch, ""};
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@
#undef min
#undef interface
#undef OPEN_EXISTING
#undef OPTIONAL

0 comments on commit 795d5de

Please sign in to comment.