Skip to content

Commit

Permalink
add formattr and >> operator for SM command line parsing.
Browse files Browse the repository at this point in the history
cxxopts use >> to parse opts.

Signed-off-by: Xiaoxi Chen <[email protected]>
  • Loading branch information
xiaoxichen committed Apr 19, 2024
1 parent 8436d39 commit aa43265
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class HomeObjectConan(ConanFile):
name = "homeobject"
version = "1.1.1"
version = "2.0.1"
homepage = "https://github.com/eBay/HomeObject"
description = "Blob Store built on HomeReplication"
topics = ("ebay")
Expand Down
53 changes: 51 additions & 2 deletions src/include/homeobject/homeobject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,24 @@ class PGManager;
class ShardManager;
ENUM(DevType, uint8_t, AUTO_DETECT = 1, HDD, NVME, UNSUPPORTED);
struct device_info_t {
explicit device_info_t(std::string name, DevType dtype = DevType::AUTO_DETECT) : path{std::filesystem::canonical(name)}, type{dtype} {}
bool operator ==(device_info_t const& rhs) const { return path == rhs.path && type == rhs.type; }
explicit device_info_t(std::string name, DevType dtype = DevType::AUTO_DETECT) :
path{std::filesystem::canonical(name)}, type{dtype} {}
device_info_t() = default;
bool operator==(device_info_t const& rhs) const { return path == rhs.path && type == rhs.type; }
friend std::istream& operator>>(std::istream& input, device_info_t& di) {
std::string i_path, i_type;
std::getline(input, i_path, ':');
std::getline(input, i_type);
di.path = std::filesystem::canonical(i_path);
if (i_type == "HDD") {
di.type = DevType::HDD;
} else if (i_type == "NVME") {
di.type = DevType::NVME;
} else {
di.type = DevType::AUTO_DETECT;
}
return input;
}
std::filesystem::path path;
DevType type;
};
Expand Down Expand Up @@ -60,3 +76,36 @@ class HomeObject {
extern std::shared_ptr< HomeObject > init_homeobject(std::weak_ptr< HomeObjectApplication >&& application);

} // namespace homeobject
//

namespace fmt {
template <>
struct formatter< homeobject::device_info_t > {
template < typename ParseContext >
constexpr auto parse(ParseContext& ctx) {
return ctx.begin();
}

template < typename FormatContext >
auto format(homeobject::device_info_t const& device, FormatContext& ctx) {
std::string type;
switch (device.type) {
case homeobject::DevType::HDD:
type = "HDD";
break;
case homeobject::DevType::NVME:
type = "NVME";
break;
case homeobject::DevType::UNSUPPORTED:
type = "UNSUPPORTED";
break;
case homeobject::DevType::AUTO_DETECT:
type = "AUTO_DETECT";
break;
default:
type = "UNKNOWN";
}
return fmt::format_to(ctx.out(), "Path: {}, Type: {}", device.path.string(), type);
}
};
} // namespace fmt

0 comments on commit aa43265

Please sign in to comment.