Skip to content

Commit

Permalink
chore: do not force include XXXOption if not use
Browse files Browse the repository at this point in the history
Signed-off-by: black-desk <me@black-desk.cn>
  • Loading branch information
black-desk committed Jan 16, 2024
1 parent 85fa1a5 commit beeaddf
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 35 deletions.
2 changes: 0 additions & 2 deletions examples/using-crun/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <exception> // for exception_ptr, exception
#include <filesystem> // for path
#include <iostream> // for basic_ostream, operator<<
#include <list> // for list, operator!=, _List...
#include <map> // for operator!=, operator==
#include <memory> // for shared_ptr, make_shared
#include <string> // for char_traits, basic_string
Expand All @@ -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
Expand Down
54 changes: 38 additions & 16 deletions include/ocppi/cli/crun/Crun.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <exception> // for exception_ptr
#include <filesystem> // for path
#include <list> // for list
#include <memory> // for make_shared, shared_ptr
#include <string> // for string
#include <vector> // for vector
Expand Down Expand Up @@ -54,44 +53,67 @@ class Crun final : public CLI {
-> tl::expected<std::unique_ptr<Crun>, std::exception_ptr>;

[[nodiscard]]
auto
state(const runtime::ContainerID &id,
const std::vector<runtime::StateOption> &opts = {}) const noexcept
auto state(const runtime::ContainerID &id) const noexcept
-> tl::expected<runtime::state::types::State,
std::exception_ptr> override;
[[nodiscard]]
auto state(const runtime::ContainerID &id,
const std::vector<runtime::StateOption> &opts) const noexcept
-> tl::expected<runtime::state::types::State,
std::exception_ptr> override;

[[nodiscard]]
auto
create(const runtime::ContainerID &id,
const std::filesystem::path &pathToBundle,
const std::vector<runtime::CreateOption> &opts = {}) noexcept
auto create(const runtime::ContainerID &id,
const std::filesystem::path &pathToBundle) noexcept
-> tl::expected<void, std::exception_ptr> override;
[[nodiscard]]
auto create(const runtime::ContainerID &id,
const std::filesystem::path &pathToBundle,
const std::vector<runtime::CreateOption> &opts) noexcept
-> tl::expected<void, std::exception_ptr> override;

[[nodiscard]]
auto start(const runtime::ContainerID &id) noexcept
-> tl::expected<void, std::exception_ptr> override;
[[nodiscard]]
auto start(const runtime::ContainerID &id,
const std::vector<runtime::StartOption> &opts = {}) noexcept
const std::vector<runtime::StartOption> &opts) noexcept
-> tl::expected<void, std::exception_ptr> override;

[[nodiscard]]
auto kill(const runtime::ContainerID &id,
const runtime::Signal &signal) noexcept
-> tl::expected<void, std::exception_ptr> override;
[[nodiscard]]
auto kill(const runtime::ContainerID &id, const runtime::Signal &signal,
const std::vector<runtime::KillOption> &opts = {}) noexcept
const std::vector<runtime::KillOption> &opts) noexcept
-> tl::expected<void, std::exception_ptr> override;

[[nodiscard]]
auto
delete_(const runtime::ContainerID &id,
const std::vector<runtime::DeleteOption> &opts = {}) noexcept
auto delete_(const runtime::ContainerID &id) noexcept
-> tl::expected<void, std::exception_ptr> override;
[[nodiscard]]
auto delete_(const runtime::ContainerID &id,
const std::vector<runtime::DeleteOption> &opts) noexcept
-> tl::expected<void, std::exception_ptr> override;

[[nodiscard]]
auto exec(const runtime::ContainerID &id, const std::string &executable,
const std::vector<std::string> &command) noexcept
-> tl::expected<void, std::exception_ptr> override;
[[nodiscard]]
auto exec(const runtime::ContainerID &id, const std::string &executable,
const std::vector<std::string> &command,
const std::vector<runtime::ExecOption> &opts = {}) noexcept
const std::vector<runtime::ExecOption> &opts) noexcept
-> tl::expected<void, std::exception_ptr> override;

[[nodiscard]]
auto list(const std::vector<runtime::ListOption> &opts = {}) noexcept
-> tl::expected<std::list<types::ContainerListItem>,
auto list() noexcept
-> tl::expected<std::vector<types::ContainerListItem>,
std::exception_ptr> override;
[[nodiscard]]
auto list(const std::vector<runtime::ListOption> &opts) noexcept
-> tl::expected<std::vector<types::ContainerListItem>,
std::exception_ptr> override;
};
}
16 changes: 12 additions & 4 deletions include/ocppi/runtime/Runtime.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <exception> // for exception_ptr
#include <list> // for list
#include <string> // for string
#include <vector> // for vector

Expand All @@ -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<std::string> &command) noexcept
-> tl::expected<void, std::exception_ptr> = 0;
[[nodiscard]]
virtual auto exec(const ContainerID &id, const std::string &executable,
const std::vector<std::string> &command,
const std::vector<ExecOption> &opts = {}) noexcept
const std::vector<ExecOption> &opts) noexcept
-> tl::expected<void, std::exception_ptr> = 0;

[[nodiscard]]
virtual auto list() noexcept
-> tl::expected<std::vector<types::ContainerListItem>,
std::exception_ptr> = 0;
[[nodiscard]]
virtual auto list(const std::vector<ListOption> &opts = {}) noexcept
-> tl::expected<std::list<types::ContainerListItem>,
virtual auto list(const std::vector<ListOption> &opts) noexcept
-> tl::expected<std::vector<types::ContainerListItem>,
std::exception_ptr> = 0;
};

Expand Down
32 changes: 23 additions & 9 deletions include/ocppi/runtime/SpecRuntime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,45 @@ class SpecRuntime {
auto operator=(SpecRuntime &&) -> SpecRuntime & = delete;

[[nodiscard]]
virtual auto
state(const ContainerID &id,
const std::vector<StateOption> &opts = {}) const noexcept
virtual auto state(const ContainerID &id) const noexcept
-> tl::expected<state::types::State, std::exception_ptr> = 0;
[[nodiscard]]
virtual auto state(const ContainerID &id,
const std::vector<StateOption> &opts) const noexcept
-> tl::expected<state::types::State, std::exception_ptr> = 0;

[[nodiscard]]
virtual auto create(const ContainerID &id,
const std::filesystem::path &pathToBundle) noexcept
-> tl::expected<void, std::exception_ptr> = 0;
[[nodiscard]]
virtual auto create(const ContainerID &id,
const std::filesystem::path &pathToBundle,
const std::vector<CreateOption> &opts = {}) noexcept
const std::vector<CreateOption> &opts) noexcept
-> tl::expected<void, std::exception_ptr> = 0;

[[nodiscard]]
virtual auto start(const ContainerID &id) noexcept
-> tl::expected<void, std::exception_ptr> = 0;
[[nodiscard]]
virtual auto start(const ContainerID &id,
const std::vector<StartOption> &opts = {}) noexcept
const std::vector<StartOption> &opts) noexcept
-> tl::expected<void, std::exception_ptr> = 0;

[[nodiscard]]
virtual auto kill(const ContainerID &id, const Signal &signal) noexcept
-> tl::expected<void, std::exception_ptr> = 0;
[[nodiscard]]
virtual auto kill(const ContainerID &id, const Signal &signal,
const std::vector<KillOption> &opts = {}) noexcept
const std::vector<KillOption> &opts) noexcept
-> tl::expected<void, std::exception_ptr> = 0;

[[nodiscard]]
virtual auto
delete_(const ContainerID &id,
const std::vector<DeleteOption> &opts = {}) noexcept
virtual auto delete_(const ContainerID &id) noexcept
-> tl::expected<void, std::exception_ptr> = 0;
[[nodiscard]]
virtual auto delete_(const ContainerID &id,
const std::vector<DeleteOption> &opts) noexcept
-> tl::expected<void, std::exception_ptr> = 0;
};

Expand Down
53 changes: 50 additions & 3 deletions src/ocppi/cli/crun/Crun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ auto doState(const std::string &bin,

}

auto Crun::state(const runtime::ContainerID &id) const noexcept
-> tl::expected<runtime::state::types::State, std::exception_ptr>
{
return this->state(id, {});
}

auto Crun::state(const runtime::ContainerID &id,
const std::vector<runtime::StateOption> &opts) const noexcept
-> tl::expected<runtime::state::types::State, std::exception_ptr>
Expand Down Expand Up @@ -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<void, std::exception_ptr>
{
return this->create(id, pathToBundle, {});
}

auto Crun::create(const runtime::ContainerID &id,
const std::filesystem::path &pathToBundle,
const std::vector<runtime::CreateOption> &opts) noexcept
Expand Down Expand Up @@ -160,6 +173,12 @@ void doStart(const std::string &bin,

}

auto Crun::start(const runtime::ContainerID &id) noexcept
-> tl::expected<void, std::exception_ptr>
{
return this->start(id, {});
}

auto Crun::start(const runtime::ContainerID &id,
const std::vector<runtime::StartOption> &opts) noexcept
-> tl::expected<void, std::exception_ptr>
Expand Down Expand Up @@ -199,6 +218,13 @@ void doKill(const std::string &bin,

}

auto Crun::kill(const runtime::ContainerID &id,
const runtime::Signal &signal) noexcept
-> tl::expected<void, std::exception_ptr>
{
return this->kill(id, signal, {});
}

auto Crun::kill(const runtime::ContainerID &id, const runtime::Signal &signal,
const std::vector<runtime::KillOption> &opts) noexcept
-> tl::expected<void, std::exception_ptr>
Expand Down Expand Up @@ -237,6 +263,12 @@ void doDelete(const std::string &bin,

}

auto Crun::delete_(const runtime::ContainerID &id) noexcept
-> tl::expected<void, std::exception_ptr>
{
return this->delete_(id, {});
}

auto Crun::delete_(const runtime::ContainerID &id,
const std::vector<runtime::DeleteOption> &opts) noexcept
-> tl::expected<void, std::exception_ptr>
Expand Down Expand Up @@ -277,6 +309,13 @@ void doExec(const std::string &bin,

}

auto Crun::exec(const runtime::ContainerID &id, const std::string &executable,
const std::vector<std::string> &command) noexcept
-> tl::expected<void, std::exception_ptr>
{
return this->exec(id, executable, command, {});
}

auto Crun::exec(const runtime::ContainerID &id, const std::string &executable,
const std::vector<std::string> &command,
const std::vector<runtime::ExecOption> &opts) noexcept
Expand All @@ -291,7 +330,7 @@ try {
namespace
{

tl::expected<std::list<types::ContainerListItem>, std::exception_ptr>
tl::expected<std::vector<types::ContainerListItem>, std::exception_ptr>
doList(const std::string &bin,
[[maybe_unused]] const std::shared_ptr<spdlog::logger> &logger,
const std::vector<runtime::ListOption> &opts)
Expand All @@ -315,13 +354,21 @@ doList(const std::string &bin,
}

auto j = nlohmann::json::parse(out_ips);
return j.get<std::list<types::ContainerListItem>>();
return j.get<std::vector<types::ContainerListItem>>();
}

}

auto Crun::list() noexcept
-> tl::expected<std::vector<types::ContainerListItem>,
std::exception_ptr>
{
return this->list({});
}

auto Crun::list(const std::vector<runtime::ListOption> &opts) noexcept
-> tl::expected<std::list<types::ContainerListItem>, std::exception_ptr>
-> tl::expected<std::vector<types::ContainerListItem>,
std::exception_ptr>
try {
return doList(this->bin(), this->logger(), opts);
} catch (...) {
Expand Down
2 changes: 1 addition & 1 deletion tools/iwyu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 {} \;

0 comments on commit beeaddf

Please sign in to comment.