Skip to content
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

Merged
merged 3 commits into from Aug 20, 2017

Conversation

Songweibin
Copy link
Contributor

@Songweibin Songweibin commented Jul 31, 2017

I get rbd list info as follows, when using --format xml.

[root@s248 ~]# rbd ls --format xml
<images><name>i1</name></images>[root@s248 ~]# 
[root@s248 ~]#

This occurs when only --format used, and after fixup as follows:

[root@s248 build]# ./bin/rbd ls --format xml
<images><name>i1</name></images>
[root@s248 build]#

If --pretty-format used while --format not works, it does not return error:

[root@s248 ~]# rbd ls --pretty-format
i1
[root@s248 ~]#

fixes: http://tracker.ceph.com/issues/21019
Signed-off-by: songweibin song.weibin@zte.com.cn

@Songweibin
Copy link
Contributor Author

Jenkins retest this please

@dillaman
Copy link

This should be in the CLI and not in the low-level formatter.

@Songweibin Songweibin force-pushed the wip-xml-format branch 2 times, most recently from cda83be to ec92b59 Compare August 1, 2017 11:47
@Songweibin Songweibin changed the title common: adding newline operation when using '--format xml' rbd: adding newline operation when only '--format' used and return error when only '--pretty-format' used Aug 1, 2017
@Songweibin
Copy link
Contributor Author

@dillaman Modified and Updated. Thanks for your review. I'm wondering if this is that you mean?

Copy link

@dillaman dillaman left a 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.

@@ -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
Copy link

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.

@@ -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]")
Copy link

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]"

@@ -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>()) {
Copy link

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

Copy link

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"

Copy link
Contributor Author

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.

Copy link

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

@Songweibin
Copy link
Contributor Author

Jenkins retest this please

}
return 0;
}

int add_newline_at_end(const po::variables_map &vm,
Copy link

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>
@Songweibin
Copy link
Contributor Author

@dillaman Oops, I misunderstood your suggestion. Already modified and repushed, thank you.

@Songweibin
Copy link
Contributor Author

Jenkins retest this please

@@ -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)
Copy link

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.

@@ -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;
Copy link

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.

@@ -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;
Copy link

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

@ceph-jenkins
Copy link
Collaborator

all commits in this PR are signed

@Songweibin
Copy link
Contributor Author

@dillaman Repushed, thanks for your review and suggestion.

@@ -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)

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

@Songweibin
Copy link
Contributor Author

@dillaman Yeah, thanks, done.

@Songweibin
Copy link
Contributor Author

Jenkins retest this please

@Songweibin Songweibin changed the title rbd: adding newline operation when only '--format' used and return error when only '--pretty-format' used misc: adding line break at end of some cli results Aug 17, 2017
@Songweibin
Copy link
Contributor Author

Jenkins retest this please

1 similar comment
@Songweibin
Copy link
Contributor Author

Jenkins retest this please

Copy link

@dillaman dillaman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@dillaman dillaman changed the title misc: adding line break at end of some cli results rbd: adding line break at end of some cli results Aug 17, 2017
@dillaman
Copy link

@Songweibin
Copy link
Contributor Author

@dillaman Updated, thank you.

Signed-off-by: songweibin <song.weibin@zte.com.cn>
Signed-off-by: songweibin <song.weibin@zte.com.cn>
@Songweibin
Copy link
Contributor Author

@Songweibin
Copy link
Contributor Author

Jenkins retest this please

@smithfarm
Copy link
Contributor

smithfarm commented Aug 18, 2017

Presumably we'd want this for luminous as well? In that case, @Songweibin can you add

Fixes: http://tracker.ceph.com/issues/21019

just above the Signed-off-by line? Thanks.

@dillaman
Copy link

@smithfarm that tracker ticket looks unrelated

@smithfarm
Copy link
Contributor

@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?

@dillaman
Copy link

@smithfarm ah -- 19dd420 was added after my last review.

@Songweibin
Copy link
Contributor Author

@dillaman @smithfarm Sorry for forget to add tracker ticket. Done, thank you so much.

@dillaman
Copy link

re-adding the needs-qa label since the addition of 19dd420 could affect multiple test suites outside of rbd

@dillaman dillaman changed the title rbd: adding line break at end of some cli results common: adding line break at end of some cli results Aug 18, 2017
@tchaikov tchaikov merged commit d81816f into ceph:master Aug 20, 2017
@Songweibin Songweibin deleted the wip-xml-format branch September 7, 2017 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants