diff options
author | Sage Weil <sage@redhat.com> | 2020-02-19 23:53:40 +0100 |
---|---|---|
committer | Sage Weil <sage@redhat.com> | 2020-02-25 02:52:31 +0100 |
commit | 41f003518a070f5518a1b729fc3596a1b7689533 (patch) | |
tree | 9a2b47424f6e2be797e0da94abab6daeed7a4541 /src | |
parent | mgr/status: align with ceph table style (diff) | |
download | ceph-41f003518a070f5518a1b729fc3596a1b7689533.tar.xz ceph-41f003518a070f5518a1b729fc3596a1b7689533.zip |
common/TextTable: only pad between columns
No need to pad on the right-hand side if there are no additional columns
that follow.
Signed-off-by: Sage Weil <sage@redhat.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/common/TextTable.cc | 12 | ||||
-rw-r--r-- | src/test/cli/crushtool/arg-order-checks.t | 74 | ||||
-rw-r--r-- | src/test/cli/osdmaptool/tree.t | 14 | ||||
-rw-r--r-- | src/test/test_texttable.cc | 8 |
4 files changed, 56 insertions, 52 deletions
diff --git a/src/common/TextTable.cc b/src/common/TextTable.cc index 8973c9e756c..e17e7eb8d1c 100644 --- a/src/common/TextTable.cc +++ b/src/common/TextTable.cc @@ -68,18 +68,22 @@ std::ostream &operator<<(std::ostream &out, const TextTable &t) { for (unsigned int i = 0; i < t.col.size(); i++) { TextTable::TextTableColumn col = t.col[i]; + if (i) { + out << t.column_separation; + } out << string(t.indent, ' ') - << pad(col.heading, col.width, col.hd_align) - << t.column_separation; + << pad(col.heading, col.width, col.hd_align); } out << endl; for (unsigned int i = 0; i < t.row.size(); i++) { for (unsigned int j = 0; j < t.row[i].size(); j++) { TextTable::TextTableColumn col = t.col[j]; + if (j) { + out << t.column_separation; + } out << string(t.indent, ' ') - << pad(t.row[i][j], col.width, col.col_align) - << t.column_separation; + << pad(t.row[i][j], col.width, col.col_align); } out << endl; } diff --git a/src/test/cli/crushtool/arg-order-checks.t b/src/test/cli/crushtool/arg-order-checks.t index a83e37196c4..ec81a4ee839 100644 --- a/src/test/cli/crushtool/arg-order-checks.t +++ b/src/test/cli/crushtool/arg-order-checks.t @@ -6,43 +6,43 @@ $ map="$TESTDIR/foo" $ crushtool --outfn "$map" --build --set-chooseleaf-vary-r 0 --set-chooseleaf-stable 0 --num_osds 25 node straw 5 rack straw 1 root straw 0 --reweight-item osd.2 99 -o "$map" --tree crushtool reweighting item osd.2 to 99 - ID CLASS WEIGHT TYPE NAME - -11 123.00000 root root - -6 103.00000 rack rack0 - -1 103.00000 node node0 - 0 1.00000 osd.0 - 1 1.00000 osd.1 - 2 99.00000 osd.2 - 3 1.00000 osd.3 - 4 1.00000 osd.4 - -7 5.00000 rack rack1 - -2 5.00000 node node1 - 5 1.00000 osd.5 - 6 1.00000 osd.6 - 7 1.00000 osd.7 - 8 1.00000 osd.8 - 9 1.00000 osd.9 - -8 5.00000 rack rack2 - -3 5.00000 node node2 - 10 1.00000 osd.10 - 11 1.00000 osd.11 - 12 1.00000 osd.12 - 13 1.00000 osd.13 - 14 1.00000 osd.14 - -9 5.00000 rack rack3 - -4 5.00000 node node3 - 15 1.00000 osd.15 - 16 1.00000 osd.16 - 17 1.00000 osd.17 - 18 1.00000 osd.18 - 19 1.00000 osd.19 - -10 5.00000 rack rack4 - -5 5.00000 node node4 - 20 1.00000 osd.20 - 21 1.00000 osd.21 - 22 1.00000 osd.22 - 23 1.00000 osd.23 - 24 1.00000 osd.24 + ID CLASS WEIGHT TYPE NAME + -11 123.00000 root root + -6 103.00000 rack rack0 + -1 103.00000 node node0 + 0 1.00000 osd.0 + 1 1.00000 osd.1 + 2 99.00000 osd.2 + 3 1.00000 osd.3 + 4 1.00000 osd.4 + -7 5.00000 rack rack1 + -2 5.00000 node node1 + 5 1.00000 osd.5 + 6 1.00000 osd.6 + 7 1.00000 osd.7 + 8 1.00000 osd.8 + 9 1.00000 osd.9 + -8 5.00000 rack rack2 + -3 5.00000 node node2 + 10 1.00000 osd.10 + 11 1.00000 osd.11 + 12 1.00000 osd.12 + 13 1.00000 osd.13 + 14 1.00000 osd.14 + -9 5.00000 rack rack3 + -4 5.00000 node node3 + 15 1.00000 osd.15 + 16 1.00000 osd.16 + 17 1.00000 osd.17 + 18 1.00000 osd.18 + 19 1.00000 osd.19 + -10 5.00000 rack rack4 + -5 5.00000 node node4 + 20 1.00000 osd.20 + 21 1.00000 osd.21 + 22 1.00000 osd.22 + 23 1.00000 osd.23 + 24 1.00000 osd.24 $ crushtool -d "$map" # begin crush map tunable choose_local_tries 0 diff --git a/src/test/cli/osdmaptool/tree.t b/src/test/cli/osdmaptool/tree.t index fa55b4a9837..387f564b00d 100644 --- a/src/test/cli/osdmaptool/tree.t +++ b/src/test/cli/osdmaptool/tree.t @@ -4,13 +4,13 @@ $ osdmaptool --tree=plain om osdmaptool: osdmap file 'om' - ID CLASS WEIGHT TYPE NAME STATUS REWEIGHT PRI-AFF - -1 3.00000 root default - -3 3.00000 rack localrack - -2 3.00000 host localhost - 0 1.00000 osd.0 DNE 0 - 1 1.00000 osd.1 DNE 0 - 2 1.00000 osd.2 DNE 0 + ID CLASS WEIGHT TYPE NAME STATUS REWEIGHT PRI-AFF + -1 3.00000 root default + -3 3.00000 rack localrack + -2 3.00000 host localhost + 0 1.00000 osd.0 DNE 0 + 1 1.00000 osd.1 DNE 0 + 2 1.00000 osd.2 DNE 0 $ osdmaptool --tree=json-pretty om osdmaptool: osdmap file 'om' diff --git a/src/test/test_texttable.cc b/src/test/test_texttable.cc index 25a82449c73..290f6f85fa9 100644 --- a/src/test/test_texttable.cc +++ b/src/test/test_texttable.cc @@ -29,7 +29,7 @@ TEST(TextTable, Alignment) { t << "1" << 2 << 3 << TextTable::endrow; std::ostringstream oss; oss << t; - ASSERT_STREQ("HEAD1 HEAD2 HEAD3 \n1 2 3 \n", oss.str().c_str()); + ASSERT_STREQ("HEAD1 HEAD2 HEAD3\n1 2 3\n", oss.str().c_str()); } TEST(TextTable, WidenAndClearShrink) { @@ -43,14 +43,14 @@ TEST(TextTable, WidenAndClearShrink) { // validate wide output std::ostringstream oss; oss << t; - ASSERT_STREQ("1 \nwider \n", oss.str().c_str()); + ASSERT_STREQ("1 \nwider\n", oss.str().c_str()); oss.str(""); // reset, validate single-char width output t.clear(); t << "s"; oss << t; - ASSERT_STREQ("1 \ns \n", oss.str().c_str()); + ASSERT_STREQ("1\ns\n", oss.str().c_str()); } TEST(TextTable, Indent) { @@ -61,7 +61,7 @@ TEST(TextTable, Indent) { t << "s"; std::ostringstream oss; oss << t; - ASSERT_STREQ(" 1 \n s \n", oss.str().c_str()); + ASSERT_STREQ(" 1\n s\n", oss.str().c_str()); } |