Skip to content

Commit

Permalink
iox-#1391 Move command line argument parser to 'cli' module
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Oct 25, 2023
1 parent 30e64be commit cb8c18c
Show file tree
Hide file tree
Showing 21 changed files with 53 additions and 88 deletions.
3 changes: 2 additions & 1 deletion iceoryx_dust/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ cc_library(
"source/**/*.cpp",
"source/**/*.hpp",
]),
hdrs = glob(["include/**"]) + glob(["container/**"]) + glob(["filesystem/**"]) + glob(["memory/**"]) + glob(["utility/**"]) + glob(["vocabulary/**"]) + [
hdrs = glob(["include/**"]) + glob(["cli/**"]) + glob(["container/**"]) + glob(["filesystem/**"]) + glob(["memory/**"]) + glob(["utility/**"]) + glob(["vocabulary/**"]) + [
":iceoryx_dust_deployment_hpp",
],
includes = [
"cli/include/",
"container/include/",
"filesystem/include/",
"include",
Expand Down
12 changes: 7 additions & 5 deletions iceoryx_dust/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ iox_add_library(
PRIVATE_LIBS_LINUX ${CODE_COVERAGE_LIBS}
PUBLIC_LIBS iceoryx_hoofs::iceoryx_hoofs
BUILD_INTERFACE ${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/cli/include
${PROJECT_SOURCE_DIR}/container/include
${PROJECT_SOURCE_DIR}/filesystem/include
${PROJECT_SOURCE_DIR}/memory/include
Expand All @@ -55,17 +56,18 @@ iox_add_library(
${CMAKE_BINARY_DIR}/generated/iceoryx_dust/include
INSTALL_INTERFACE include/${PREFIX}
EXPORT_INCLUDE_DIRS include/
cli/include/
container/include/
filesystem/include/
memory/include/
utility/include/
vocabulary/include/
FILES
source/cli/arguments.cpp
source/cli/command_line_parser.cpp
source/cli/option.cpp
source/cli/option_definition.cpp
source/cli/option_manager.cpp
cli/source/arguments.cpp
cli/source/command_line_parser.cpp
cli/source/option.cpp
cli/source/option_definition.cpp
cli/source/option_manager.cpp
filesystem/source/file_reader.cpp
source/posix_wrapper/named_pipe.cpp
source/posix_wrapper/signal_watcher.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,22 @@
#ifndef IOX_DUST_CLI_ARGUMENTS_HPP
#define IOX_DUST_CLI_ARGUMENTS_HPP

#include "iceoryx_dust/cli/types.hpp"
#include "iceoryx_dust/cxx/convert.hpp"
#include "iceoryx_dust/internal/cli/option.hpp"
#include "iox/cli/option.hpp"
#include "iox/cli/types.hpp"
#include "iox/expected.hpp"
#include "iox/vector.hpp"

namespace iox
{
namespace cli
{
namespace internal
{
/// @brief This class provides access to the command line argument values.
/// When constructed with the default constructor it is empty. Calling
/// CommandLineParser::parse creates and returns a populated Arguments
/// object.
/// This class should never be used directly. Use the CommandLine builder
/// from 'iceoryx_hoofs/cxx/command_line_argument_definition.hpp' to create a struct which contains
/// from 'iox/cli_definition.hpp' to create a struct which contains
/// the values.
class Arguments
{
Expand Down Expand Up @@ -69,9 +67,8 @@ class Arguments
const char* m_binaryName;
vector<Option, MAX_NUMBER_OF_ARGUMENTS> m_arguments;
};
} // namespace internal
} // namespace cli
} // namespace iox

#include "iceoryx_dust/internal/cli/arguments.inl"
#include "iox/cli/arguments.inl"
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
#ifndef IOX_DUST_CLI_COMMAND_LINE_OPTION_VALUE_INL
#define IOX_DUST_CLI_COMMAND_LINE_OPTION_VALUE_INL

#include "iceoryx_dust/internal/cli/arguments.hpp"
#include "iox/cli/arguments.hpp"

namespace iox
{
namespace cli
{
namespace internal
{
template <typename T>
inline expected<T, Arguments::Error> Arguments::convertFromString(const Argument_t& stringValue) const noexcept
{
Expand Down Expand Up @@ -61,7 +59,6 @@ inline expected<T, Arguments::Error> Arguments::get(const OptionName_t& optionNa

return err(Error::NO_SUCH_VALUE);
}
} // namespace internal
} // namespace cli
} // namespace iox

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@
#ifndef IOX_DUST_CLI_COMMAND_PARSER_HPP
#define IOX_DUST_CLI_COMMAND_PARSER_HPP

#include "iceoryx_dust/internal/cli/arguments.hpp"
#include "iceoryx_dust/internal/cli/option_definition.hpp"
#include "iox/cli/arguments.hpp"
#include "iox/cli/option_definition.hpp"
#include <cstdint>

namespace iox
{
namespace cli
{
namespace internal
{
/// @brief Factory class for the CommandLineOption. First, one has to register
/// all switches and options before calling parse. This is required for
/// the help page which is generated and printed on failure as well as
Expand Down Expand Up @@ -89,7 +87,6 @@ Arguments parseCommandLineArguments(const OptionDefinition& optionSet,
char* argv[],
const uint64_t argcOffset = 1U) noexcept;

} // namespace internal
} // namespace cli
} // namespace iox

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
#ifndef IOX_DUST_CLI_OPTION_HPP
#define IOX_DUST_CLI_OPTION_HPP

#include "iceoryx_dust/cli/types.hpp"
#include "iox/cli/types.hpp"

namespace iox
{
namespace cli
{
namespace internal
{
/// @brief Represents a command line option
struct Option
{
Expand Down Expand Up @@ -96,7 +94,6 @@ struct OptionWithDetails : public Option // can this be melt together
TypeName_t typeName;
} details;
};
} // namespace internal
} // namespace cli
} // namespace iox
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#ifndef IOX_DUST_CLI_OPTION_DEFINITION_HPP
#define IOX_DUST_CLI_OPTION_DEFINITION_HPP

#include "iceoryx_dust/cli/types.hpp"
#include "iceoryx_dust/internal/cli/arguments.hpp"
#include "iox/cli/arguments.hpp"
#include "iox/cli/types.hpp"
#include "iox/function.hpp"
#include "iox/vector.hpp"
#include <cstdint>
Expand All @@ -27,8 +27,6 @@ namespace iox
{
namespace cli
{
namespace internal
{
/// @brief A set of options which is provided to the CommandLineParser.
/// Description, short and long name as well as type and value can be defined for every
/// command line option which the application provides.
Expand Down Expand Up @@ -94,7 +92,6 @@ class OptionDefinition
};

std::ostream& operator<<(std::ostream& stream, const OptionWithDetails& value) noexcept;
} // namespace internal
} // namespace cli
} // namespace iox

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#ifndef IOX_DUST_CLI_OPTION_MANAGER_HPP
#define IOX_DUST_CLI_OPTION_MANAGER_HPP

#include "iceoryx_dust/internal/cli/command_line_parser.hpp"
#include "iceoryx_dust/internal/cli/option_definition.hpp"
#include "iox/cli/command_line_parser.hpp"
#include "iox/cli/option_definition.hpp"
#include "iox/function.hpp"
#include "iox/std_string_support.hpp"
#include "iox/vector.hpp"
Expand All @@ -26,8 +26,6 @@ namespace iox
{
namespace cli
{
namespace internal
{
using CmdAssignments_t = vector<function<void(Arguments&)>, MAX_NUMBER_OF_ARGUMENTS>;

/// @brief Manages command line options which were defined via the IOX_CLI_ macros in a
Expand Down Expand Up @@ -82,9 +80,8 @@ class OptionManager
const OptionType optionType);
};

} // namespace internal
} // namespace cli
} // namespace iox

#include "iceoryx_dust/internal/cli/option_manager.inl"
#include "iox/cli/option_manager.inl"
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
#ifndef IOX_DUST_CLI_OPTION_MANAGER_INL
#define IOX_DUST_CLI_OPTION_MANAGER_INL

#include "iceoryx_dust/internal/cli/option_manager.hpp"
#include "iox/cli/option_manager.hpp"

namespace iox
{
namespace cli
{
namespace internal
{
template <typename T>
inline T OptionManager::extractOptionArgumentValue(const Arguments& arguments,
const char shortName,
Expand Down Expand Up @@ -73,7 +71,6 @@ inline T OptionManager::defineOption(T& referenceToMember,

return defaultArgumentValue;
}
} // namespace internal
} // namespace cli
} // namespace iox

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_DUST_CLI_COMMAND_LINE_ARGUMENT_DEFINITION_HPP
#define IOX_DUST_CLI_COMMAND_LINE_ARGUMENT_DEFINITION_HPP

#include "iceoryx_dust/internal/cli/option_manager.hpp"
#ifndef IOX_DUST_CLI_CLI_DEFINITION_HPP
#define IOX_DUST_CLI_CLI_DEFINITION_HPP

#include "iox/cli/option_manager.hpp"

#define IOX_INTERNAL_CMD_LINE_VALUE(type, memberName, defaultValue, shortName, longName, description, optionType) \
public: \
Expand Down Expand Up @@ -95,7 +96,7 @@
/// @endcode
#define IOX_CLI_DEFINITION(Name) \
private: \
Name(::iox::cli::internal::OptionManager& optionManager, int argc, char* argv[], const uint64_t argcOffset = 1U) \
Name(::iox::cli::OptionManager& optionManager, int argc, char* argv[], const uint64_t argcOffset = 1U) \
: m_optionManager{&optionManager} \
{ \
m_optionManager->populateDefinedOptions(m_binaryName, argc, argv, argcOffset); \
Expand All @@ -109,7 +110,7 @@
const uint64_t argcOffset = 1U, \
const ::iox::function<void()> onFailureCallback = [] { std::exit(EXIT_FAILURE); }) \
{ \
::iox::cli::internal::OptionManager optionManager(programDescription, onFailureCallback); \
::iox::cli::OptionManager optionManager(programDescription, onFailureCallback); \
return Name(optionManager, argc, argv, argcOffset); \
} \
\
Expand All @@ -119,8 +120,8 @@
} \
\
private: \
::iox::cli::internal::OptionManager* m_optionManager = nullptr; \
::iox::cli::OptionManager* m_optionManager = nullptr; \
const char* m_binaryName = nullptr


#endif
#endif // IOX_DUST_CLI_COMMAND_LINE_ARGUMENT_DEFINITION_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_dust/internal/cli/arguments.hpp"
#include "iox/cli/arguments.hpp"

namespace iox
{
namespace cli
{
namespace internal
{
const char* Arguments::binaryName() const noexcept
{
return m_binaryName;
Expand All @@ -38,6 +36,5 @@ bool Arguments::isSwitchSet(const OptionName_t& switchName) const noexcept
}
return false;
}
} // namespace internal
} // namespace cli
} // namespace iox
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_dust/internal/cli/command_line_parser.hpp"
#include "iox/cli/command_line_parser.hpp"
#include "iceoryx_hoofs/error_handling/error_handling.hpp"
#include "iox/algorithm.hpp"
#include "iox/std_string_support.hpp"
Expand All @@ -25,8 +25,6 @@ namespace iox
{
namespace cli
{
namespace internal
{
Arguments
parseCommandLineArguments(const OptionDefinition& optionSet, int argc, char* argv[], const uint64_t argcOffset) noexcept
{
Expand Down Expand Up @@ -377,6 +375,5 @@ void CommandLineParser::printHelpAndExit() const noexcept
m_optionSet->m_onFailureCallback();
}

} // namespace internal
} // namespace cli
} // namespace iox
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_dust/internal/cli/option.hpp"
#include "iox/cli/option.hpp"

namespace iox
{
namespace cli
{
namespace internal
{
bool Option::isEmpty() const noexcept
{
return longOption.empty() && shortOption == NO_SHORT_OPTION;
Expand Down Expand Up @@ -98,6 +96,5 @@ bool OptionWithDetails::operator<(const OptionWithDetails& rhs) const noexcept
{
return Option::operator<(rhs);
}
} // namespace internal
} // namespace cli
} // namespace iox
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_dust/internal/cli/option_definition.hpp"
#include "iox/cli/option_definition.hpp"
#include "iox/std_string_support.hpp"

namespace iox
{
namespace cli
{
namespace internal
{
OptionDefinition::OptionDefinition(const OptionDescription_t& programDescription,
const function<void()> onFailureCallback) noexcept
: m_programDescription{programDescription}
Expand Down Expand Up @@ -141,6 +139,5 @@ std::ostream& operator<<(std::ostream& stream, const OptionWithDetails& option)

return stream;
}
} // namespace internal
} // namespace cli
} // namespace iox
Loading

0 comments on commit cb8c18c

Please sign in to comment.