From 4b33841858bd18b8eec15d7b1706c9e8f79d0922 Mon Sep 17 00:00:00 2001 From: Colin Baumgarten Date: Mon, 18 Mar 2024 13:44:03 +0100 Subject: [PATCH] cli_auto_up: Partly fix handling of mountpoints The cli_auto_up command right now does not properly handle mountpoints. Fix the case when going up one level inside of a mounted module. Note that this does not yet fix the case where the current level is the top-level of the mounted module. In that case the up command should switch to the presence container that holds the mounted module. Instead it switches all the way up to the topmost level, so it has the same effect as the top command. --- apps/cli/cli_auto.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/cli/cli_auto.c b/apps/cli/cli_auto.c index 6b9d9351..7d1cbc3d 100644 --- a/apps/cli/cli_auto.c +++ b/apps/cli/cli_auto.c @@ -248,12 +248,14 @@ cli_auto_up(clixon_handle h, cvec *cvv1 = NULL; /* copy */ char *api_path_fmt0; /* from */ char *api_path_fmt1; /* to */ + char *api_path_fmt2 = NULL; /* 'to' with mountpoint prepended */ char *api_path = NULL; int i; int j; size_t len; cvec *cvv_filter = NULL; yang_stmt *yspec0; + char *mtpoint = ""; if (cvec_len(argv) != 1){ clixon_err(OE_PLUGIN, EINVAL, "Usage: %s()", __FUNCTION__); @@ -313,15 +315,26 @@ cli_auto_up(clixon_handle h, cv = cvec_i(cvv0, i); cvec_append_var(cvv1, cv); } - /* get api-path and xpath */ - if (api_path_fmt2api_path(api_path_fmt1, cvv1, yspec0, &api_path, NULL) < 0) - goto done; + clicon_data_get(h, "cli-edit-mtpoint", &mtpoint); + if (strlen(mtpoint)) { + if (mtpoint_paths(yspec0, mtpoint, api_path_fmt1, &api_path_fmt2) < 0) + goto done; + if (api_path_fmt2api_path(api_path_fmt2, cvv1, yspec0, &api_path, NULL) < 0) + goto done; + } + else{ + /* get api-path and xpath */ + if (api_path_fmt2api_path(api_path_fmt1, cvv1, yspec0, &api_path, NULL) < 0) + goto done; + } /* Store this as edit-mode */ clicon_data_set(h, "cli-edit-mode", api_path); clicon_data_cvec_set(h, "cli-edit-cvv", cvv1); ok: retval = 0; done: + if (api_path_fmt2) + free(api_path_fmt2); if (api_path) free(api_path); return retval;