From 9ba866ad44905cb2f07b1ee316ca6001fbbaf0e6 Mon Sep 17 00:00:00 2001 From: black-desk Date: Tue, 16 Jan 2024 16:30:21 +0800 Subject: [PATCH] chore: do not force include XXXOption if not use Signed-off-by: black-desk --- examples/using-crun/src/main.cpp | 2 - include/ocppi/cli/crun/Crun.hpp | 54 +++++++++++++++++++-------- include/ocppi/runtime/Runtime.hpp | 16 ++++++-- include/ocppi/runtime/SpecRuntime.hpp | 32 +++++++++++----- src/ocppi/cli/crun/Crun.cpp | 53 ++++++++++++++++++++++++-- tools/iwyu.sh | 2 +- 6 files changed, 124 insertions(+), 35 deletions(-) diff --git a/examples/using-crun/src/main.cpp b/examples/using-crun/src/main.cpp index d09022d..f5081ff 100644 --- a/examples/using-crun/src/main.cpp +++ b/examples/using-crun/src/main.cpp @@ -5,7 +5,6 @@ #include // for exception_ptr, exception #include // for path #include // for basic_ostream, operator<< -#include // for list, operator!=, _List... #include // for operator!=, operator== #include // for shared_ptr, make_shared #include // for char_traits, basic_string @@ -20,7 +19,6 @@ #include "ocppi/cli/CLI.hpp" // for CLI #include "ocppi/cli/crun/Crun.hpp" // for Crun #include "ocppi/runtime/ContainerID.hpp" // for ContainerID -#include "ocppi/runtime/ListOption.hpp" // IWYU pragma: keep #include "ocppi/runtime/Signal.hpp" // for Signal #include "ocppi/runtime/state/types/Generators.hpp" // IWYU pragma: keep #include "ocppi/types/ContainerListItem.hpp" // for ContainerListItem diff --git a/include/ocppi/cli/crun/Crun.hpp b/include/ocppi/cli/crun/Crun.hpp index c91134e..90e2fe0 100644 --- a/include/ocppi/cli/crun/Crun.hpp +++ b/include/ocppi/cli/crun/Crun.hpp @@ -2,7 +2,6 @@ #include // for exception_ptr #include // for path -#include // for list #include // for make_shared, shared_ptr #include // for string #include // for vector @@ -54,44 +53,67 @@ class Crun final : public CLI { -> tl::expected, std::exception_ptr>; [[nodiscard]] - auto - state(const runtime::ContainerID &id, - const std::vector &opts = {}) const noexcept + auto state(const runtime::ContainerID &id) const noexcept + -> tl::expected override; + [[nodiscard]] + auto state(const runtime::ContainerID &id, + const std::vector &opts) const noexcept -> tl::expected override; [[nodiscard]] - auto - create(const runtime::ContainerID &id, - const std::filesystem::path &pathToBundle, - const std::vector &opts = {}) noexcept + auto create(const runtime::ContainerID &id, + const std::filesystem::path &pathToBundle) noexcept + -> tl::expected override; + [[nodiscard]] + auto create(const runtime::ContainerID &id, + const std::filesystem::path &pathToBundle, + const std::vector &opts) noexcept -> tl::expected override; [[nodiscard]] + auto start(const runtime::ContainerID &id) noexcept + -> tl::expected override; + [[nodiscard]] auto start(const runtime::ContainerID &id, - const std::vector &opts = {}) noexcept + const std::vector &opts) noexcept -> tl::expected override; [[nodiscard]] + auto kill(const runtime::ContainerID &id, + const runtime::Signal &signal) noexcept + -> tl::expected override; + [[nodiscard]] auto kill(const runtime::ContainerID &id, const runtime::Signal &signal, - const std::vector &opts = {}) noexcept + const std::vector &opts) noexcept -> tl::expected override; [[nodiscard]] - auto - delete_(const runtime::ContainerID &id, - const std::vector &opts = {}) noexcept + auto delete_(const runtime::ContainerID &id) noexcept + -> tl::expected override; + [[nodiscard]] + auto delete_(const runtime::ContainerID &id, + const std::vector &opts) noexcept -> tl::expected override; [[nodiscard]] + auto exec(const runtime::ContainerID &id, const std::string &executable, + const std::vector &command) noexcept + -> tl::expected override; + [[nodiscard]] auto exec(const runtime::ContainerID &id, const std::string &executable, const std::vector &command, - const std::vector &opts = {}) noexcept + const std::vector &opts) noexcept -> tl::expected override; [[nodiscard]] - auto list(const std::vector &opts = {}) noexcept - -> tl::expected, + auto list() noexcept + -> tl::expected, + std::exception_ptr> override; + [[nodiscard]] + auto list(const std::vector &opts) noexcept + -> tl::expected, std::exception_ptr> override; }; } diff --git a/include/ocppi/runtime/Runtime.hpp b/include/ocppi/runtime/Runtime.hpp index c2f6c9f..f029378 100644 --- a/include/ocppi/runtime/Runtime.hpp +++ b/include/ocppi/runtime/Runtime.hpp @@ -1,7 +1,6 @@ #pragma once #include // for exception_ptr -#include // for list #include // for string #include // for vector @@ -25,13 +24,22 @@ namespace ocppi::runtime class Runtime : public SpecRuntime { public: [[nodiscard]] + virtual auto exec(const ContainerID &id, const std::string &executable, + const std::vector &command) noexcept + -> tl::expected = 0; + [[nodiscard]] virtual auto exec(const ContainerID &id, const std::string &executable, const std::vector &command, - const std::vector &opts = {}) noexcept + const std::vector &opts) noexcept -> tl::expected = 0; + + [[nodiscard]] + virtual auto list() noexcept + -> tl::expected, + std::exception_ptr> = 0; [[nodiscard]] - virtual auto list(const std::vector &opts = {}) noexcept - -> tl::expected, + virtual auto list(const std::vector &opts) noexcept + -> tl::expected, std::exception_ptr> = 0; }; diff --git a/include/ocppi/runtime/SpecRuntime.hpp b/include/ocppi/runtime/SpecRuntime.hpp index f215481..d60292b 100644 --- a/include/ocppi/runtime/SpecRuntime.hpp +++ b/include/ocppi/runtime/SpecRuntime.hpp @@ -33,31 +33,45 @@ class SpecRuntime { auto operator=(SpecRuntime &&) -> SpecRuntime & = delete; [[nodiscard]] - virtual auto - state(const ContainerID &id, - const std::vector &opts = {}) const noexcept + virtual auto state(const ContainerID &id) const noexcept + -> tl::expected = 0; + [[nodiscard]] + virtual auto state(const ContainerID &id, + const std::vector &opts) const noexcept -> tl::expected = 0; [[nodiscard]] + virtual auto create(const ContainerID &id, + const std::filesystem::path &pathToBundle) noexcept + -> tl::expected = 0; + [[nodiscard]] virtual auto create(const ContainerID &id, const std::filesystem::path &pathToBundle, - const std::vector &opts = {}) noexcept + const std::vector &opts) noexcept -> tl::expected = 0; [[nodiscard]] + virtual auto start(const ContainerID &id) noexcept + -> tl::expected = 0; + [[nodiscard]] virtual auto start(const ContainerID &id, - const std::vector &opts = {}) noexcept + const std::vector &opts) noexcept -> tl::expected = 0; [[nodiscard]] + virtual auto kill(const ContainerID &id, const Signal &signal) noexcept + -> tl::expected = 0; + [[nodiscard]] virtual auto kill(const ContainerID &id, const Signal &signal, - const std::vector &opts = {}) noexcept + const std::vector &opts) noexcept -> tl::expected = 0; [[nodiscard]] - virtual auto - delete_(const ContainerID &id, - const std::vector &opts = {}) noexcept + virtual auto delete_(const ContainerID &id) noexcept + -> tl::expected = 0; + [[nodiscard]] + virtual auto delete_(const ContainerID &id, + const std::vector &opts) noexcept -> tl::expected = 0; }; diff --git a/src/ocppi/cli/crun/Crun.cpp b/src/ocppi/cli/crun/Crun.cpp index 11d24c3..45ecd2f 100644 --- a/src/ocppi/cli/crun/Crun.cpp +++ b/src/ocppi/cli/crun/Crun.cpp @@ -80,6 +80,12 @@ auto doState(const std::string &bin, } +auto Crun::state(const runtime::ContainerID &id) const noexcept + -> tl::expected +{ + return this->state(id, {}); +} + auto Crun::state(const runtime::ContainerID &id, const std::vector &opts) const noexcept -> tl::expected @@ -121,6 +127,13 @@ void doCreate(const std::string &bin, } +auto Crun::create(const runtime::ContainerID &id, + const std::filesystem::path &pathToBundle) noexcept + -> tl::expected +{ + return this->create(id, pathToBundle, {}); +} + auto Crun::create(const runtime::ContainerID &id, const std::filesystem::path &pathToBundle, const std::vector &opts) noexcept @@ -160,6 +173,12 @@ void doStart(const std::string &bin, } +auto Crun::start(const runtime::ContainerID &id) noexcept + -> tl::expected +{ + return this->start(id, {}); +} + auto Crun::start(const runtime::ContainerID &id, const std::vector &opts) noexcept -> tl::expected @@ -199,6 +218,13 @@ void doKill(const std::string &bin, } +auto Crun::kill(const runtime::ContainerID &id, + const runtime::Signal &signal) noexcept + -> tl::expected +{ + return this->kill(id, signal, {}); +} + auto Crun::kill(const runtime::ContainerID &id, const runtime::Signal &signal, const std::vector &opts) noexcept -> tl::expected @@ -237,6 +263,12 @@ void doDelete(const std::string &bin, } +auto Crun::delete_(const runtime::ContainerID &id) noexcept + -> tl::expected +{ + return this->delete_(id, {}); +} + auto Crun::delete_(const runtime::ContainerID &id, const std::vector &opts) noexcept -> tl::expected @@ -277,6 +309,13 @@ void doExec(const std::string &bin, } +auto Crun::exec(const runtime::ContainerID &id, const std::string &executable, + const std::vector &command) noexcept + -> tl::expected +{ + return this->exec(id, executable, command, {}); +} + auto Crun::exec(const runtime::ContainerID &id, const std::string &executable, const std::vector &command, const std::vector &opts) noexcept @@ -291,7 +330,7 @@ try { namespace { -tl::expected, std::exception_ptr> +tl::expected, std::exception_ptr> doList(const std::string &bin, [[maybe_unused]] const std::shared_ptr &logger, const std::vector &opts) @@ -315,13 +354,21 @@ doList(const std::string &bin, } auto j = nlohmann::json::parse(out_ips); - return j.get>(); + return j.get>(); } } +auto Crun::list() noexcept + -> tl::expected, + std::exception_ptr> +{ + return this->list({}); +} + auto Crun::list(const std::vector &opts) noexcept - -> tl::expected, std::exception_ptr> + -> tl::expected, + std::exception_ptr> try { return doList(this->bin(), this->logger(), opts); } catch (...) { diff --git a/tools/iwyu.sh b/tools/iwyu.sh index f9c3b9d..f712752 100755 --- a/tools/iwyu.sh +++ b/tools/iwyu.sh @@ -54,5 +54,5 @@ CLANG_FORMAT=${CLANG_FORMAT:=$({ echo "clang-format" })} -find . -regex '.*\.\(cpp\|hpp\|cc\|cxx\|h\)' \ +find . -regex '.*\.\(cpp\|hpp\|cc\|cxx\|h\)' -not -path "./tools/*" \ -exec "$CLANG_FORMAT" -style=file -i {} \;