Skip to content

Commit

Permalink
refactor: use fmt:join to simplify code (apache#1680)
Browse files Browse the repository at this point in the history
This is a patch to simplify code, also to check whether the previous patch(5e9a2a9) works.

Note: In `{{{}}}`, `{{` and `}}` are used to escape, the left `{}` is used for `replacement fields`,
see https://fmt.dev/latest/syntax.html.
  • Loading branch information
acelyc111 authored Nov 13, 2023
1 parent dbd5f20 commit 97bde42
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions src/client/replication_ddl_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>

#include "backup_types.h"
#include "common//duplication_common.h"
Expand All @@ -46,6 +45,7 @@
#include "common/replication_common.h"
#include "common/replication_enums.h"
#include "fmt/core.h"
#include "fmt/format.h"
#include "meta/meta_rpc_types.h"
#include "runtime/api_layer1.h"
#include "runtime/rpc/group_address.h"
Expand Down Expand Up @@ -1138,34 +1138,13 @@ dsn::error_code replication_ddl_client::enable_backup_policy(const std::string &
}
}

// help functions

// TODO (yingchun) use join
template <typename T>
// make sure T support cout << T;
std::string print_set(const std::set<T> &set)
{
std::stringstream ss;
ss << "{";
auto begin = set.begin();
auto end = set.end();
for (auto it = begin; it != end; it++) {
if (it != begin) {
ss << ", ";
}
ss << *it;
}
ss << "}";
return ss.str();
}

static void print_policy_entry(const policy_entry &entry)
{
dsn::utils::table_printer tp;
tp.add_row_name_and_data(" name", entry.policy_name);
tp.add_row_name_and_data(" backup_provider_type", entry.backup_provider_type);
tp.add_row_name_and_data(" backup_interval", entry.backup_interval_seconds + "s");
tp.add_row_name_and_data(" app_ids", print_set(entry.app_ids));
tp.add_row_name_and_data(" app_ids", fmt::format("{{{}}}", fmt::join(entry.app_ids, ", ")));
tp.add_row_name_and_data(" start_time", entry.start_time);
tp.add_row_name_and_data(" status", entry.is_disable ? "disabled" : "enabled");
tp.add_row_name_and_data(" backup_history_count", entry.backup_history_count_to_keep);
Expand All @@ -1188,7 +1167,7 @@ static void print_backup_entry(const backup_entry &bentry)
tp.add_row_name_and_data(" id", bentry.backup_id);
tp.add_row_name_and_data(" start_time", start_time);
tp.add_row_name_and_data(" end_time", end_time);
tp.add_row_name_and_data(" app_ids", print_set(bentry.app_ids));
tp.add_row_name_and_data(" app_ids", fmt::format("{{{}}}", fmt::join(bentry.app_ids, ", ")));
tp.output(std::cout);
}

Expand Down

0 comments on commit 97bde42

Please sign in to comment.