Skip to content

Commit

Permalink
*: Fixup ttable_vty_finish to take a string to print when no output
Browse files Browse the repository at this point in the history
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 <sharpd@nvidia.com>
  • Loading branch information
donaldsharp committed Feb 16, 2024
1 parent 4b26411 commit cc2fb38
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 81 deletions.
4 changes: 2 additions & 2 deletions bgpd/bgp_bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2684,7 +2684,7 @@ DEFPY(show_bmp,
uptime, &ba->addrsrc);
continue;
}
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);

vty_out(vty, "\n %zu connected clients:\n",
bmp_session_count(&bt->sessions));
Expand All @@ -2708,7 +2708,7 @@ DEFPY(show_bmp,
bmp->cnt_mirror_overruns,
total, q, kq);
}
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);

vty_out(vty, "\n");
}
Expand Down
11 changes: 4 additions & 7 deletions isisd/isis_spf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2856,12 +2856,9 @@ void isis_print_routes(struct vty *vty, struct isis_spftree *spftree,
json != NULL);
}

if (!json) {
if (tt->nrows > 1)
ttable_vty_finish(vty, &tt, "\n");
else
ttable_del(tt);
} else {
if (!json)
ttable_vty_finish(vty, &tt, "\n", NULL);
else {
*json = ttable_json(tt, prefix_sid ? "sdssdsdd" : "sdsss");
ttable_del(tt);
}
Expand Down Expand Up @@ -3231,7 +3228,7 @@ static void isis_print_frr_summary(struct vty *vty,
isis_print_frr_summary_line_coverage(tt, "Protection coverage",
coverage, coverage_total);

ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}

static void show_isis_frr_summary_common(struct vty *vty, int levels,
Expand Down
5 changes: 1 addition & 4 deletions isisd/isis_sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1059,10 +1059,7 @@ static void show_node(struct vty *vty, struct isis_area *area, int level,
buf, cap->msd);
}

if (tt->nrows > 1)
ttable_vty_finish(vty, &tt, "\n");
else
ttable_del(tt);
ttable_vty_finish(vty, &tt, "\n", NULL);
}

DEFUN(show_sr_node, show_sr_node_cmd,
Expand Down
5 changes: 1 addition & 4 deletions isisd/isis_srv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,7 @@ static void show_node(struct vty *vty, struct isis_area *area, int level)
cap->srv6_msd.max_end_d_msd);
}

if (tt->nrows > 1) {
ttable_vty_finish(vty, &tt, "\n");
} else
ttable_del(tt);
ttable_vty_finish(vty, &tt, "\n", NULL);
}

DEFUN(show_srv6_node, show_srv6_node_cmd,
Expand Down
10 changes: 2 additions & 8 deletions lib/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,15 +440,9 @@ DEFUN_NOSH(show_hash_stats,
vty_out(vty, "# allocated: %d\n", _hashes->count);
vty_out(vty, "# named: %d\n\n", tt->nrows - 1);

if (tt->nrows > 1) {
ttable_colseps(tt, 0, RIGHT, true, '|');
ttable_colseps(tt, 0, RIGHT, true, '|');

ttable_vty_finish(vty, &tt, "\n");
} else {
vty_out(vty, "No named hash tables to display.\n");

ttable_del(tt);
}
ttable_vty_finish(vty, &tt, "\n", "No named hash tables to display.\n");

return CMD_SUCCESS;
}
Expand Down
27 changes: 6 additions & 21 deletions lib/northbound_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,12 +1303,8 @@ static int nb_cli_show_transactions(struct vty *vty)
return CMD_WARNING;
}

if (tt->nrows > 1) {
ttable_vty_finish(vty, &tt, "\n");
} else {
vty_out(vty, "No configuration transactions to display.\n\n");
ttable_del(tt);
}
ttable_vty_finish(vty, &tt, "\n",
"No configuration transactions to display.\n\n");

return CMD_SUCCESS;
}
Expand Down Expand Up @@ -1577,16 +1573,10 @@ DEFPY (show_yang_module,
module->ns);
}

/* Dump the generated table. */
if (tt->nrows > 1) {
if (tt->nrows > 1)
vty_out(vty, " Flags: I - Implemented, D - Deviated\n\n");

ttable_vty_finish(vty, &tt, "\n");
} else {
vty_out(vty, "No YANG modules to display.\n\n");

ttable_del(tt);
}
ttable_vty_finish(vty, &tt, "\n", "No YANG modules to display.\n\n");

return CMD_SUCCESS;
}
Expand Down Expand Up @@ -1686,13 +1676,8 @@ DEFPY (show_yang_module_translator,
}
}

if (tt->nrows > 1)
ttable_vty_finish(vty, &tt, "\n");
else {
vty_out(vty, "No YANG module translators to display.\n\n");

ttable_del(tt);
}
ttable_vty_finish(vty, &tt, "\n",
"No YANG module translators to display.\n\n");

return CMD_SUCCESS;
}
Expand Down
13 changes: 9 additions & 4 deletions lib/termtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,18 @@ void ttable_rowseps(struct ttable *tt, unsigned int row,
}
}

void ttable_vty_finish(struct vty *vty, struct ttable **tt, const char *newline)
void ttable_vty_finish(struct vty *vty, struct ttable **tt, const char *newline,
const char *display_if_no_rows)
{
char *out = ttable_dump(*tt, newline);
if ((*tt)->nrows > 1) {
char *out = ttable_dump(*tt, newline);

vty_out(vty, "%s", out);
vty_out(vty, "%s", out);

XFREE(MTYPE_TMP, out);
} else if (display_if_no_rows)
vty_out(vty, "%s", display_if_no_rows);

XFREE(MTYPE_TMP, out);
ttable_del(*tt);

*tt = NULL;
Expand Down
4 changes: 3 additions & 1 deletion lib/termtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,10 @@ char *ttable_dump(struct ttable *tt, const char *newline);
* @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
*/
void ttable_vty_finish(struct vty *vty, struct ttable **tt, const char *newline);
void ttable_vty_finish(struct vty *vty, struct ttable **tt, const char *newline,
const char *display_if_no_rows);

/**
* Convert a table to a JSON array of objects.
Expand Down
2 changes: 1 addition & 1 deletion pathd/path_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ DEFPY(show_srte_policy,
: "Inactive");
}

ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);

return CMD_SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion pathd/path_pcep_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ static int path_pcep_cli_show_srte_pcep_counters(struct vty *vty)
}
}

ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);

pcep_lib_free_counters(group);

Expand Down
4 changes: 2 additions & 2 deletions pimd/pim6_mld.c
Original file line number Diff line number Diff line change
Expand Up @@ -2533,7 +2533,7 @@ static void gm_show_if_vrf(struct vty *vty, struct vrf *vrf, const char *ifname,
}

if (!js && !detail)
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}

static void gm_show_if(struct vty *vty, struct vrf *vrf, const char *ifname,
Expand Down Expand Up @@ -3011,7 +3011,7 @@ static void gm_show_groups(struct vty *vty, struct vrf *vrf, bool uj)
if (uj)
vty_json(vty, json);
else
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}

DEFPY(gm_show_mld_groups,
Expand Down
36 changes: 18 additions & 18 deletions pimd/pim_cmd_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ void pim_show_rpf(struct pim_instance *pim, struct vty *vty, json_object *json)
}
}
if (!json)
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}

void pim_show_neighbors_secondary(struct pim_instance *pim, struct vty *vty)
Expand Down Expand Up @@ -1005,7 +1005,7 @@ void pim_show_neighbors_secondary(struct pim_instance *pim, struct vty *vty)
}
}

ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}

void pim_show_state(struct pim_instance *pim, struct vty *vty,
Expand Down Expand Up @@ -1255,7 +1255,7 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty,
#if PIM_IPV == 4
vty_out(vty, "\n");
#else
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
#endif
}
}
Expand Down Expand Up @@ -1484,7 +1484,7 @@ void pim_show_upstream(struct pim_instance *pim, struct vty *vty,
}

if (!json)
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}

static void pim_show_join_desired_helper(struct pim_instance *pim,
Expand Down Expand Up @@ -1555,7 +1555,7 @@ void pim_show_join_desired(struct pim_instance *pim, struct vty *vty, bool uj)
if (uj)
vty_json(vty, json);
else
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}

void pim_show_upstream_rpf(struct pim_instance *pim, struct vty *vty, bool uj)
Expand Down Expand Up @@ -1628,7 +1628,7 @@ void pim_show_upstream_rpf(struct pim_instance *pim, struct vty *vty, bool uj)
if (uj)
vty_json(vty, json);
else
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}

static void pim_show_join_helper(struct pim_interface *pim_ifp,
Expand Down Expand Up @@ -1805,7 +1805,7 @@ void pim_show_join(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg,
}
/* Dump the generated table. */
if (!json)
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}

static void pim_show_jp_agg_helper(struct interface *ifp,
Expand Down Expand Up @@ -1879,7 +1879,7 @@ void pim_show_jp_agg_list(struct pim_instance *pim, struct vty *vty)
}
}

ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}

int pim_show_membership_cmd_helper(const char *vrf, struct vty *vty, bool uj)
Expand Down Expand Up @@ -2018,7 +2018,7 @@ void pim_show_membership(struct pim_instance *pim, struct vty *vty, bool uj)
}
json_object_free(json);

ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}
}

Expand Down Expand Up @@ -2118,7 +2118,7 @@ void pim_show_channel(struct pim_instance *pim, struct vty *vty, bool uj)
if (uj)
vty_json(vty, json);
else
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}

int pim_show_channel_cmd_helper(const char *vrf, struct vty *vty, bool uj)
Expand Down Expand Up @@ -2295,7 +2295,7 @@ void pim_show_interfaces(struct pim_instance *pim, struct vty *vty, bool mlag,
}
json_object_free(json);

ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}
}

Expand Down Expand Up @@ -2762,7 +2762,7 @@ static int pim_print_vty_pnc_cache_walkcb(struct hash_bucket *bucket, void *arg)
#endif
}

ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);

return CMD_SUCCESS;
}
Expand Down Expand Up @@ -3238,7 +3238,7 @@ void pim_show_neighbors(struct pim_instance *pim, struct vty *vty,
}

if (!json)
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}

int gm_process_query_max_response_time_cmd(struct vty *vty,
Expand Down Expand Up @@ -3529,7 +3529,7 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty,
}

if (!json)
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}

void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim, struct vty *vty)
Expand Down Expand Up @@ -3963,7 +3963,7 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg,
}

if (!json)
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}

static void show_mroute_count_per_channel_oil(struct channel_oil *c_oil,
Expand Down Expand Up @@ -4040,7 +4040,7 @@ void show_mroute_count(struct pim_instance *pim, struct vty *vty,
show_mroute_count_per_channel_oil(&sr->c_oil, json, tt);

if (!json)
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}

void show_mroute_summary(struct pim_instance *pim, struct vty *vty,
Expand Down Expand Up @@ -5337,7 +5337,7 @@ static void pim_show_group_rp_mappings_info(struct pim_instance *pim,
}

if (tt)
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);

if (!bsm_rpinfos_count(bsgrp->bsrp_list) && !uj)
vty_out(vty, "Active List is empty.\n");
Expand Down Expand Up @@ -5385,7 +5385,7 @@ static void pim_show_group_rp_mappings_info(struct pim_instance *pim,
}

if (tt)
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);

if (!bsm_rpinfos_count(bsgrp->partial_bsrp_list) && !uj)
vty_out(vty, "Partial List is empty\n");
Expand Down
2 changes: 1 addition & 1 deletion pimd/pim_rp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ void pim_rp_show_information(struct pim_instance *pim, struct prefix *range,
}

if (!json)
ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
else {
if (prev_rp_info && json_rp_rows)
json_object_object_addf(json, json_rp_rows, "%pPA",
Expand Down
4 changes: 2 additions & 2 deletions vrrpd/vrrp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ static void vrrp_show(struct vty *vty, struct vrrp_vrouter *vr)
}
}

ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);
}

/*
Expand Down Expand Up @@ -688,7 +688,7 @@ DEFPY_YANG(vrrp_vrid_show_summary,
: "Backup");
}

ttable_vty_finish(vty, &tt, "\n");
ttable_vty_finish(vty, &tt, "\n", NULL);

list_delete(&ll);

Expand Down
Loading

0 comments on commit cc2fb38

Please sign in to comment.