Browse Source

First and other keys can be shown with or without statement

Serj Kalichev 1 year ago
parent
commit
9a8dfd994f
3 changed files with 9 additions and 27 deletions
  1. 4 21
      src/pline.c
  2. 1 2
      src/pline.h
  3. 4 4
      src/show.c

+ 4 - 21
src/pline.c

@@ -346,25 +346,6 @@ size_t list_num_of_keys(const struct lysc_node *node)
 }
 
 
-bool_t list_key_with_stmt(const struct lysc_node *node, uint32_t flags)
-{
-	bool_t with_stmt = BOOL_FALSE;
-	size_t keys_num = 0;
-
-	// Parse keys's statement or not
-	keys_num = list_num_of_keys(node);
-	if (keys_num > 1) {
-		if (flags & PPARSE_MULTI_KEYS_W_STMT)
-			with_stmt = BOOL_TRUE;
-	} else {
-		if (flags & PPARSE_SINGLE_KEY_W_STMT)
-			with_stmt = BOOL_TRUE;
-	}
-
-	return with_stmt;
-}
-
-
 static bool_t pline_parse_module(const struct lys_module *module, faux_argv_t *argv,
 	pline_t *pline, uint32_t flags)
 {
@@ -457,7 +438,7 @@ static bool_t pline_parse_module(const struct lys_module *module, faux_argv_t *a
 			// Next element
 			if (!is_rollback) {
 				bool_t break_upper_loop = BOOL_FALSE;
-				bool_t with_stmt = list_key_with_stmt(node, flags);
+				bool_t first_key = BOOL_TRUE;
 
 				LY_LIST_FOR(lysc_node_child(node), iter) {
 					char *tmp = NULL;
@@ -471,7 +452,8 @@ static bool_t pline_parse_module(const struct lys_module *module, faux_argv_t *a
 					assert (leaf->type->basetype != LY_TYPE_EMPTY);
 
 					// Parse statement if necessary
-					if (with_stmt) {
+					if ((first_key && (flags & PPARSE_FIRST_KEY_W_STMT)) ||
+						(!first_key && (flags & PPARSE_MULTI_KEYS_W_STMT))) {
 						// Completion
 						if (!str) {
 							pline_add_compl(pline,
@@ -486,6 +468,7 @@ static bool_t pline_parse_module(const struct lys_module *module, faux_argv_t *a
 
 						pexpr->pat = PAT_LIST_KEY_INCOMPLETED;
 					}
+					first_key = BOOL_FALSE;
 
 					// Completion
 					if (!str) {

+ 1 - 2
src/pline.h

@@ -112,7 +112,7 @@ typedef struct pline_s {
 
 // Parse options
 typedef enum {
-	PPARSE_SINGLE_KEY_W_STMT	= 0x00000001,
+	PPARSE_FIRST_KEY_W_STMT		= 0x00000001,
 	PPARSE_MULTI_KEYS_W_STMT	= 0x00000002,
 	PPARSE_JUNIPER_SHOW		= 0x00010000,
 } pparse_flags_e;
@@ -133,7 +133,6 @@ void pline_debug(pline_t *pline);
 void pline_print_completions(const pline_t *pline, bool_t help);
 
 size_t num_of_keys(const struct lysc_node *node);
-bool_t list_key_with_stmt(const struct lysc_node *node, uint32_t flags);
 
 C_DECL_END
 

+ 4 - 4
src/show.c

@@ -75,24 +75,24 @@ static void show_container(const struct lyd_node *node, size_t level, uint32_t f
 static void show_list(const struct lyd_node *node, size_t level, uint32_t flags)
 {
 	size_t keys_num = 0;
-	bool_t with_stmt = BOOL_FALSE;
 	const struct lyd_node *iter = NULL;
+	bool_t first_key = BOOL_TRUE;
 
 	if (!node)
 		return;
 
 	printf("%*s%s", (int)(level * LEVEL_SPACES_NUM), "", node->schema->name);
 
-	with_stmt = list_key_with_stmt(node->schema, flags);
-
 	LY_LIST_FOR(lyd_child(node), iter) {
 		if (!(iter->schema->nodetype & LYS_LEAF))
 			continue;
 		if (!(iter->schema->flags & LYS_KEY))
 			continue;
-		if (with_stmt)
+		if ((first_key && (flags & PPARSE_FIRST_KEY_W_STMT)) ||
+			(!first_key && (flags & PPARSE_MULTI_KEYS_W_STMT)))
 			printf(" %s", iter->schema->name);
 		printf(" %s", get_value(iter));
+		first_key = BOOL_FALSE;
 	}
 	printf("%s\n", JUN(flags) ? " {" : "");
 	show_subtree(lyd_child(node), level + 1, flags);