diff options
| author | Igor Ryzhov <iryzhov@nfware.com> | 2021-03-23 16:16:01 +0300 |
|---|---|---|
| committer | Igor Ryzhov <iryzhov@nfware.com> | 2021-03-23 16:24:40 +0300 |
| commit | c6f1f711bf885a6d110d22ebe8c647c5ff95c688 (patch) | |
| tree | ac2c05dab7c858b5cddbd839e0612f1aba4b8ed9 /lib/northbound_cli.c | |
| parent | 634aa8253ea224d094f4a0aab01126cbd79c811e (diff) | |
lib: add ability to sort CLI commands printed by NB layer
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'lib/northbound_cli.c')
| -rw-r--r-- | lib/northbound_cli.c | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c index efb8877488..f88c2161da 100644 --- a/lib/northbound_cli.c +++ b/lib/northbound_cli.c @@ -553,10 +553,55 @@ void nb_cli_show_config_prepare(struct nb_config *config, bool with_defaults) static void show_dnode_children_cmds(struct vty *vty, struct lyd_node *root, bool with_defaults) { + struct nb_node *nb_node, *sort_node = NULL; + struct listnode *listnode; struct lyd_node *child; + struct list *sort_list; + void *data; + + LY_TREE_FOR (root->child, child) { + nb_node = child->schema->priv; + + /* + * We finished processing current list, + * it's time to print the config. + */ + if (sort_node && nb_node != sort_node) { + for (ALL_LIST_ELEMENTS_RO(sort_list, listnode, data)) + nb_cli_show_dnode_cmds(vty, data, + with_defaults); + + list_delete(&sort_list); + sort_node = NULL; + } + + /* + * If the config needs to be sorted, + * then add the dnode to the sorting + * list for later processing. + */ + if (nb_node && nb_node->cbs.cli_cmp) { + if (!sort_node) { + sort_node = nb_node; + sort_list = list_new(); + sort_list->cmp = (int (*)(void *, void *)) + nb_node->cbs.cli_cmp; + } + + listnode_add_sort(sort_list, child); + continue; + } - LY_TREE_FOR (root->child, child) nb_cli_show_dnode_cmds(vty, child, with_defaults); + } + + if (sort_node) { + for (ALL_LIST_ELEMENTS_RO(sort_list, listnode, data)) + nb_cli_show_dnode_cmds(vty, data, with_defaults); + + list_delete(&sort_list); + sort_node = NULL; + } } void nb_cli_show_dnode_cmds(struct vty *vty, struct lyd_node *root, |
