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

Ttable vty finish #15386

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

donaldsharp
Copy link
Member

Add a ttable_vty_finish function that encapsulates common coding patterns. See the individual commits for details.

Consistent pattern was this:

	out = ttable_dump(tt, "\n");
	vty_out(vty, "%s", out);
	XFREE(MTYPE_TMP, out);
	ttable_del(tt);

Let's just consolidate this pattern into ttable_vty_finish.
Since no-one ever used it any other way.

Signed-off-by: Donald Sharp <[email protected]>
There is another common pattern in the usage of ttable_vty_finish
that is this:
	if (tt->nrows > 1) {
		ttable_vty_finish(vty, &tt, "\n");
	} else {
		vty_out(vty, "No configuration transactions to display.\n\n");
		ttable_del(tt);
	}

Let's move this into the ttable_vty_finish function and let
callers specify the string to use when the table is empty.

Signed-off-by: Donald Sharp <[email protected]>
Copy link
Member

@ton31337 ton31337 left a comment

Choose a reason for hiding this comment

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

LGTM

@ton31337
Copy link
Member

Valid failures though.

void ttable_vty_finish(struct vty *vty, struct ttable **tt, const char *newline,
const char *display_if_no_rows)
{
if ((*tt)->nrows > 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't dig too deeply but should this really be > 1 rather than > 0?

* @param tt - double pointer to the table to dump, this pointer
* is freed.
* @param newline the desired newline sequence to use, null terminated.
* @param display_if_no_rows The string to display if nrows is 0
Copy link
Contributor

Choose a reason for hiding this comment

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

This description is incorrect as it will currently (perhaps erroneously) display the string if nrows is 0 or 1.

Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Copy link

This PR is stale because it has been open 180 days with no activity. Comment or remove the autoclose label in order to avoid having this PR closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants