Skip to content

Commit

Permalink
iox-eclipse-iceoryx#2130 Move 'cli' types from 'iceoryx_dust' to 'ice…
Browse files Browse the repository at this point in the history
…oryx_hoofs'
  • Loading branch information
elBoberido committed Dec 12, 2023
1 parent 726128f commit c3677c0
Show file tree
Hide file tree
Showing 24 changed files with 145 additions and 110 deletions.
3 changes: 3 additions & 0 deletions .clang-tidy-diff-scans.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
./iceoryx_hoofs/test/moduletests/test_cxx*
./iceoryx_hoofs/source/cxx/*

./iceoryx_hoofs/cli/**/*
./iceoryx_hoofs/test/moduletests/test_cli_*

./iceoryx_hoofs/memory/**/*
./iceoryx_hoofs/test/moduletests/test_memory_*

Expand Down
19 changes: 2 additions & 17 deletions iceoryx_dust/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,8 @@ set(PREFIX iceoryx/v${CMAKE_PROJECT_VERSION})
########## build iceoryx dust lib ##########
#

iox_add_library(
TARGET iceoryx_dust
NAMESPACE iceoryx_dust
PROJECT_PREFIX ${PREFIX}
PRIVATE_LIBS ${ICEORYX_SANITIZER_FLAGS}
PRIVATE_LIBS_LINUX ${CODE_COVERAGE_LIBS}
PUBLIC_LIBS iceoryx_hoofs::iceoryx_hoofs
BUILD_INTERFACE ${PROJECT_SOURCE_DIR}/cli/include
INSTALL_INTERFACE include/${PREFIX}
EXPORT_INCLUDE_DIRS cli/include/
FILES
cli/source/arguments.cpp
cli/source/command_line_parser.cpp
cli/source/option.cpp
cli/source/option_definition.cpp
cli/source/option_manager.cpp
)
add_library(iceoryx_dust INTERFACE)
add_library(iceoryx_dust::iceoryx_dust ALIAS iceoryx_dust)

#
########## dust testing ##########
Expand Down
4 changes: 3 additions & 1 deletion iceoryx_hoofs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ configure_version(
cc_library(
name = "iceoryx_hoofs",
srcs = glob([
"cli/source/*.cpp",
"design/source/*.cpp",
"filesystem/source/*.cpp",
"memory/source/*.cpp",
Expand All @@ -56,12 +57,13 @@ cc_library(
"utility/source/*.cpp",
"vocabulary/source/**/*.cpp",
]),
hdrs = glob(["include/**"]) + glob(["legacy/**"]) + glob(["memory/**"]) + glob(["container/**"]) + glob(["vocabulary/**"]) + glob(["time/**"]) + glob(["utility/**"]) + glob(["primitives/**"]) + glob(["posix/**"]) + glob(["design/**"]) + glob(["buffer/**"]) + glob(["filesystem/**"]) + glob(["functional/**"]) + glob(["reporting/**"]) + [
hdrs = glob(["include/**"]) + glob(["legacy/**"]) + glob(["cli/**"]) + glob(["memory/**"]) + glob(["container/**"]) + glob(["vocabulary/**"]) + glob(["time/**"]) + glob(["utility/**"]) + glob(["primitives/**"]) + glob(["posix/**"]) + glob(["design/**"]) + glob(["buffer/**"]) + glob(["filesystem/**"]) + glob(["functional/**"]) + glob(["reporting/**"]) + [
":iceoryx_hoofs_deployment_hpp",
":iceoryx_versions_h",
],
includes = [
"buffer/include/",
"cli/include/",
"container/include/",
"design/include",
"filesystem/include",
Expand Down
7 changes: 7 additions & 0 deletions iceoryx_hoofs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ iox_add_library(
PRIVATE_LIBS_LINUX acl atomic ${CODE_COVERAGE_LIBS}
BUILD_INTERFACE ${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/legacy/include
${PROJECT_SOURCE_DIR}/cli/include
${PROJECT_SOURCE_DIR}/memory/include
${PROJECT_SOURCE_DIR}/container/include
${PROJECT_SOURCE_DIR}/vocabulary/include
Expand All @@ -74,6 +75,7 @@ iox_add_library(
INSTALL_INTERFACE include/${PREFIX}
EXPORT_INCLUDE_DIRS include/
legacy/include/
cli/include/
memory/include/
container/include/
vocabulary/include/
Expand All @@ -95,6 +97,11 @@ iox_add_library(
posix/utility/include/
posix/vocabulary/include/
FILES
cli/source/arguments.cpp
cli/source/command_line_parser.cpp
cli/source/option.cpp
cli/source/option_definition.cpp
cli/source/option_manager.cpp
design/source/functional_interface.cpp
filesystem/source/file_reader.cpp
filesystem/source/filesystem.cpp
Expand Down
10 changes: 9 additions & 1 deletion iceoryx_hoofs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ The module structure is a logical grouping. It is replicated for `concurrent` an
|`filesystem` | | Implementation of C++17 filesystem features for instance `iox::access_rights` and `iox::perms` to abstract file permissions |
|`PosixAcl` | i | Interface for Access Control Lists (ACL). |
|`FileLock` | | File lock C++ wrapping class. |
|`FileReader` | Wrapper for opening files and reading them. |
|`FileReader` | | Wrapper for opening files and reading them. |

### Functional (functional)

Expand All @@ -83,6 +83,7 @@ The module structure is a logical grouping. It is replicated for `concurrent` an
|`convert` | i | Converting a number into a string is easy, converting it back can be hard. You can use functions like `strtoll`, but you still have to handle errors like under- and overflow, or converting invalid strings into number. Here we abstract all the error handling so that you can convert strings into numbers safely. |
|`into` | i | |
|`Scheduler` | i | Supported schedulers and functions to get their priority range are contained here. |
|`serialization` | i | Implements a simple serialization concept for classes based on the idea presented here [ISOCPP serialization](https://isocpp.org/wiki/faq/serialization#serialize-text-format). |

### Primitives (primitives)

Expand Down Expand Up @@ -189,6 +190,13 @@ setTimeout(5_ms); // 5 milliseconds
|`posix_group` | | Access to user information. |
|`posix_user` | | Access to group information. |
### Comand line interface (cli)
| component | internal | description |
|:---------------------:|:--------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|`cli_definition` | | Classes and macros to create command line interfaces. |
<center>
[Check out iceoryx_hoofs on GitHub :fontawesome-brands-github:](https://github.com/eclipse-iceoryx/iceoryx/tree/master/iceoryx_hoofs/){ .md-button } <!--NOLINT required only for the website, github URL required-->
</center>
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_DUST_CLI_ARGUMENTS_HPP
#define IOX_DUST_CLI_ARGUMENTS_HPP

#ifndef IOX_HOOFS_CLI_ARGUMENTS_HPP
#define IOX_HOOFS_CLI_ARGUMENTS_HPP

#include "iox/cli/option.hpp"
#include "iox/cli/types.hpp"
Expand Down Expand Up @@ -72,4 +73,4 @@ class Arguments

#include "iox/cli/arguments.inl"

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

#ifndef IOX_DUST_CLI_CLI_DEFINITION_INL
#define IOX_DUST_CLI_CLI_DEFINITION_INL
#ifndef IOX_HOOFS_CLI_CLI_DEFINITION_INL
#define IOX_HOOFS_CLI_CLI_DEFINITION_INL

#include "iox/cli/arguments.hpp"

Expand All @@ -26,7 +26,9 @@ namespace cli
template <typename T>
inline expected<T, Arguments::Error> Arguments::convertFromString(const Argument_t& stringValue) const noexcept
{
T value;
// @todo iox-#2055 there are edge cases which lead to not initializing the value even when the return value of
// 'fromString' is true; value initialization can be removed when #2055 is fixed
T value{};
if (!convert::fromString(stringValue.c_str(), value))
{
std::cout << "\"" << stringValue.c_str() << "\" could not be converted to the requested type" << std::endl;
Expand Down Expand Up @@ -63,4 +65,4 @@ inline expected<T, Arguments::Error> Arguments::get(const OptionName_t& optionNa
} // namespace cli
} // namespace iox

#endif // IOX_DUST_CLI_CLI_DEFINITION_INL
#endif // IOX_HOOFS_CLI_CLI_DEFINITION_INL
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_DUST_CLI_COMMAND_PARSER_HPP
#define IOX_DUST_CLI_COMMAND_PARSER_HPP

#ifndef IOX_HOOFS_CLI_COMMAND_PARSER_HPP
#define IOX_HOOFS_CLI_COMMAND_PARSER_HPP

#include "iox/cli/arguments.hpp"
#include "iox/cli/option_definition.hpp"
Expand All @@ -35,17 +36,17 @@ class CommandLineParser

private:
friend class OptionManager;
friend Arguments parseCommandLineArguments(const OptionDefinition&, int, char*[], const uint64_t) noexcept;
friend Arguments parseCommandLineArguments(const OptionDefinition&, int, char**, const uint64_t) noexcept;

/// @brief Parses the arguments from the command line.
/// Calls onFailureCallback in optionSet when the command line arguments contain illegal syntax or required
/// values are not provided and prints the help.
/// @param[in] optionSet the user defined options, based on those options the Arguments object is
/// generated
/// @param[in] argc number of arguments, see int main(int argc, char*argv[])
/// @param[in] argv the string array of arguments, see int main(int argc, char*argv[])
/// @param[in] argc number of arguments, see int main(int argc, char** argv)
/// @param[in] argv the string array of arguments, see int main(int argc, char** argv)
/// @param[in] argcOffset the starting point for the parsing. 1U starts at the first argument.
Arguments parse(const OptionDefinition& optionSet, int argc, char* argv[], const uint64_t argcOffset = 1U) noexcept;
Arguments parse(const OptionDefinition& optionSet, int argc, char** argv, const uint64_t argcOffset = 1U) noexcept;

void printHelpAndExit() const noexcept;

Expand All @@ -55,7 +56,7 @@ class CommandLineParser
/// to improve the readability of the code. None of those functions verify
/// the pre conditions they require, this has to be done by calling them
/// in the correct order.
bool doesFitIntoString(const char* value, const uint64_t maxLength) const noexcept;
static bool doesFitIntoString(const char* value, const uint64_t maxLength) noexcept;
bool areAllRequiredValuesPresent() const noexcept;
bool hasArguments(const uint64_t argc) const noexcept;
bool doesOptionStartWithDash(const char* option) const noexcept;
Expand Down Expand Up @@ -84,10 +85,10 @@ class CommandLineParser
/// @copydoc CommandLineParser::parse()
Arguments parseCommandLineArguments(const OptionDefinition& optionSet,
int argc,
char* argv[],
char** argv,
const uint64_t argcOffset = 1U) noexcept;

} // namespace cli
} // namespace iox

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

#ifndef IOX_DUST_CLI_OPTION_HPP
#define IOX_DUST_CLI_OPTION_HPP
#ifndef IOX_HOOFS_CLI_OPTION_HPP
#define IOX_HOOFS_CLI_OPTION_HPP

#include "iox/cli/types.hpp"

Expand Down Expand Up @@ -97,4 +97,4 @@ struct OptionWithDetails : public Option // can this be melt together
} // namespace cli
} // namespace iox

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

#ifndef IOX_DUST_CLI_OPTION_DEFINITION_HPP
#define IOX_DUST_CLI_OPTION_DEFINITION_HPP
#ifndef IOX_HOOFS_CLI_OPTION_DEFINITION_HPP
#define IOX_HOOFS_CLI_OPTION_DEFINITION_HPP

#include "iox/cli/arguments.hpp"
#include "iox/cli/types.hpp"
Expand All @@ -37,10 +37,10 @@ class OptionDefinition
/// @brief The constructor.
/// @param[in] programDescription The description to the program. Will be printed in the help.
/// @param[in] onFailureCallback callback which is called when parse fails, if nothing is
/// defined std::exit(EXIT_FAILURE) is called
/// defined std::quick_exit(EXIT_FAILURE) is called
explicit OptionDefinition(
const OptionDescription_t& programDescription,
const function<void()> onFailureCallback = [] { std::exit(EXIT_FAILURE); }) noexcept;
const function_ref<void()> onFailureCallback = [] { std::quick_exit(EXIT_FAILURE); }) noexcept;

/// @brief Adds a command line switch argument
/// Calls the onFailureCallback when the option was already added or the shortOption and longOption are
Expand Down Expand Up @@ -91,8 +91,8 @@ class OptionDefinition
function<void()> m_onFailureCallback;
};

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

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

#ifndef IOX_DUST_CLI_OPTION_MANAGER_HPP
#define IOX_DUST_CLI_OPTION_MANAGER_HPP
#ifndef IOX_HOOFS_CLI_OPTION_MANAGER_HPP
#define IOX_HOOFS_CLI_OPTION_MANAGER_HPP

#include "iox/cli/command_line_parser.hpp"
#include "iox/cli/option_definition.hpp"
Expand All @@ -40,7 +40,7 @@ class OptionManager
/// @param[in] programDescription the description of the application
/// @param[in] onFailureCallback callback which is called when a syntax error occurs, a required option is missing
/// or the wrong type as argument value is provided
OptionManager(const OptionDescription_t& programDescription, const function<void()> onFailureCallback);
OptionManager(const OptionDescription_t& programDescription, const function_ref<void()> onFailureCallback);

/// @brief Defines a new option
/// @param[in] referenceToMember an uninitialized piece of memory where later the content is stored when
Expand All @@ -61,10 +61,10 @@ class OptionManager

/// @brief populates all defined options
/// @param[in] binaryName the name of the binary
/// @param[in] argc the argument count taken from int main(int argc, char*argv[])
/// @param[in] argv the argument array ptr taken from int main(int argc, char*argv[])
/// @param[in] argc the argument count taken from int main(int argc, char** argv)
/// @param[in] argv the argument array ptr taken from int main(int argc, char** argv)
/// @param[in] argcOffset the offset from which the arguments should be parsed
void populateDefinedOptions(const char*& binaryName, int argc, char* argv[], const uint64_t argcOffset);
void populateDefinedOptions(const char*& binaryName, int argc, char** argv, const uint64_t argcOffset);

private:
CommandLineParser m_parser;
Expand All @@ -86,4 +86,4 @@ class OptionManager

#include "iox/cli/option_manager.inl"

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

#ifndef IOX_DUST_CLI_OPTION_MANAGER_INL
#define IOX_DUST_CLI_OPTION_MANAGER_INL

#ifndef IOX_HOOFS_CLI_OPTION_MANAGER_INL
#define IOX_HOOFS_CLI_OPTION_MANAGER_INL
#pragma once
#include "iox/cli/option_manager.hpp"

namespace iox
Expand Down Expand Up @@ -51,6 +51,8 @@ inline bool OptionManager::extractOptionArgumentValue(const Arguments& arguments
}

template <typename T>
// NOLINTJUSTIFICATION this is not a user facing API but hidden in a macro
// NOLINTNEXTLINE(readability-function-size)
inline T OptionManager::defineOption(T& referenceToMember,
const char shortName,
const OptionName_t& name,
Expand All @@ -74,4 +76,4 @@ inline T OptionManager::defineOption(T& referenceToMember,
} // namespace cli
} // namespace iox

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

#ifndef IOX_DUST_CLI_TYPES_HPP
#define IOX_DUST_CLI_TYPES_HPP
#ifndef IOX_HOOFS_CLI_TYPES_HPP
#define IOX_HOOFS_CLI_TYPES_HPP

#include "iceoryx_platform/platform_settings.hpp"
#include "iox/string.hpp"
Expand Down Expand Up @@ -52,4 +52,4 @@ using TypeName_t = string<MAX_TYPE_NAME_LENGTH>;
} // namespace cli
} // namespace iox

#endif // IOX_DUST_CLI_TYPES_HPP
#endif // IOX_HOOFS_CLI_TYPES_HPP
Loading

0 comments on commit c3677c0

Please sign in to comment.