New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
common: adding line break at end of some cli results #16687
Conversation
Jenkins retest this please |
This should be in the CLI and not in the low-level formatter. |
cda83be
to
ec92b59
Compare
@dillaman Modified and Updated. Thanks for your review. I'm wondering if this is that you mean? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nicer to add a setter to the JSON and XML formatter to optionally add a newline at the end. That way, only Utils.cc needs to be updated to enable that option.
doc/man/8/rbd.rst
Outdated
@@ -120,7 +120,8 @@ Parameters | |||
|
|||
.. option:: --pretty-format | |||
|
|||
Make json or xml formatted output more human-readable. | |||
Make json or xml formatted output more human-readable, and it only works |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: seems redundant to me since it already states it's for making json or xml output.
src/tools/rbd/ArgumentTypes.cc
Outdated
@@ -332,7 +332,7 @@ void add_no_progress_option(boost::program_options::options_description *opt) { | |||
|
|||
void add_format_options(boost::program_options::options_description *opt) { | |||
opt->add_options() | |||
(FORMAT.c_str(), po::value<Format>(), "output format [plain, json, or xml]") | |||
(FORMAT.c_str(), po::value<Format>(), "output format [default: plain, json, or xml]") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: probably should make it "output format (plain, json, or xml) [default: plain]"
src/tools/rbd/Utils.cc
Outdated
@@ -832,6 +832,10 @@ int get_formatter(const po::variables_map &vm, | |||
<< "is json or xml" << std::endl; | |||
return -EINVAL; | |||
} | |||
} else if (vm[at::PRETTY_FORMAT].as<bool>()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: should be vm[at::PRETTY_FORMAT].count() > 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: doesn't stop a user from running "--format plain --pretty-format"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems vm[at::PRETTY_FORMAT].count()
(or maybe I missed something in it) is wrong when compiling and vm.count(at::PRETTY_FORMAT)
always equal to 1, I used vm[at::PRETTY_FORMAT].as<bool>() > 0
.
Others have been updated, thanks for your review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah -- it probably has a default specified
ec92b59
to
c091ed4
Compare
Jenkins retest this please |
src/tools/rbd/Utils.cc
Outdated
} | ||
return 0; | ||
} | ||
|
||
int add_newline_at_end(const po::variables_map &vm, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was suggesting adding a boolean setter to the Formatter
that would be enabled by the rbd CLI if using json / xml non-pretty formatter.
Signed-off-by: songweibin <song.weibin@zte.com.cn>
c091ed4
to
3ee6ea8
Compare
@dillaman Oops, I misunderstood your suggestion. Already modified and repushed, thank you. |
Jenkins retest this please |
src/common/Formatter.cc
Outdated
@@ -117,8 +117,10 @@ void Formatter::dump_format_unquoted(const char *name, const char *fmt, ...) | |||
|
|||
// ----------------------- | |||
|
|||
JSONFormatter::JSONFormatter(bool p) | |||
: m_pretty(p), m_is_pending_string(false) | |||
JSONFormatter::JSONFormatter(bool pretty, bool format) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can you just add a setter method (i.e. enable_line_break()
) -- I'd like to avoid creating new defaulted parameters.
src/common/Formatter.h
Outdated
@@ -128,12 +128,14 @@ namespace ceph { | |||
std::stringstream m_ss, m_pending_string; | |||
std::list<json_formatter_stack_entry_d> m_stack; | |||
bool m_is_pending_string; | |||
bool m_format; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: m_format
is pretty generic sounding -- perhaps something like m_line_break_enabled
or similar.
src/tools/rbd/ArgumentTypes.h
Outdated
@@ -111,7 +111,7 @@ struct Format : public TypedValue<std::string> { | |||
|
|||
Format(const std::string &format) : TypedValue<std::string>(format) {} | |||
|
|||
Formatter create_formatter(bool pretty) const; | |||
Formatter create_formatter(bool pretty, bool format) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: seems like it's always going to be true
so no need for a new param
3ee6ea8
to
e48b641
Compare
all commits in this PR are signed |
@dillaman Repushed, thanks for your review and suggestion. |
src/common/Formatter.cc
Outdated
@@ -326,6 +328,8 @@ void XMLFormatter::flush(std::ostream& os) | |||
* we should NOT output a newline. This primarily triggers on HTTP redirects */ | |||
if (m_pretty && !m_ss_str.empty()) | |||
os << "\n"; | |||
if (m_line_break_enabled) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: else if
to avoid possibility of a double line break if in the future someone enables it and doesn't guard against pretty printing also being enabled
e48b641
to
87e76e4
Compare
@dillaman Yeah, thanks, done. |
Jenkins retest this please |
Jenkins retest this please |
1 similar comment
Jenkins retest this please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
84c20d6
to
19dd420
Compare
@dillaman Updated, thank you. |
Signed-off-by: songweibin <song.weibin@zte.com.cn>
Signed-off-by: songweibin <song.weibin@zte.com.cn>
tests contain formatted-output.yaml: http://pulpito.ceph.com/xxg-2017-08-18_04:25:36-rbd-wip-xxg-working-distro-basic-smithi/ |
Jenkins retest this please |
Presumably we'd want this for luminous as well? In that case, @Songweibin can you add
just above the |
@smithfarm that tracker ticket looks unrelated |
@dillaman Does 19dd420 not fix http://tracker.ceph.com/issues/21019 ? If not, then perhaps @Songweibin could open a new tracker ticket for this PR and write "luminous" in the backport field? |
@smithfarm ah -- 19dd420 was added after my last review. |
@dillaman @smithfarm Sorry for forget to add tracker ticket. Done, thank you so much. |
re-adding the |
I get rbd list info as follows, when using
--format xml
.This occurs when only
--format
used, and after fixup as follows:If
--pretty-format
used while--format
not works, it does not return error:fixes: http://tracker.ceph.com/issues/21019
Signed-off-by: songweibin song.weibin@zte.com.cn