From 519fe1f5762c3869ddb2c6dd36593b59b2be3ce9 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 18 Jan 2022 12:22:44 +0100 Subject: [PATCH] * CLI-spec variable `CLICON_PROMPT` `%W` changed semantics due to long prompt * From "Full Working edit path" to "Last element of working path" * New `%w` has "Full working path" --- CHANGELOG.md | 3 +++ apps/cli/cli_plugin.c | 22 ++++++++++++++++++++-- test/test_autocli_editmode.sh | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4892c9b8..2cb7ab13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,9 @@ Planned: January, 2022 Users may have to change how they access the system +* CLI-spec variable `CLICON_PROMPT` `%W` changed semantics due to long prompt + * From "Full Working edit path" to "Last element of working path" + * New `%w` has "Full working path" * Auto-cli edit-modes changed * Edit modes only for list and container nodes * Change cli spec entry to `edit @datamodelmode, cli_auto_edit("basemodel");` diff --git a/apps/cli/cli_plugin.c b/apps/cli/cli_plugin.c index 467021e4..ccb612d6 100644 --- a/apps/cli/cli_plugin.c +++ b/apps/cli/cli_plugin.c @@ -308,7 +308,7 @@ cli_load_syntax_file(clicon_handle h, fclose(f); /* Get CLICON specific global variables: * CLICON_MODE: which mode(s) this syntax applies to - * CLICON_PROMPT: Cli prompt in this mode + * CLICON_PROMPT: Cli prompt in this mode (see cli_prompt_get) * CLICON_PLUGIN: Name of C API plugin * Note: the base case is that it is: * (1) a single mode or @@ -677,7 +677,25 @@ cli_prompt_get(clicon_handle h, strcpy(tty, "notty"); cprintf(cb, "%s", tty); break; - case 'W': /* working edit path */ + case 'W': /* Last element of working path */ + if (clicon_data_get(h, "cli-edit-mode", &path) == 0 && + strlen(path)){ + int i; + + for (i=strlen(path)-1; i>=0; i--) + if (path[i] == '/' || path[i] == ':') + /* see yang2api_path_fmt_1() why occasional trailing / */ + if (i < strlen(path)-1) + break; + if (i >= 0) + cprintf(cb, "%s", &path[i+1]); + else + cprintf(cb, "%s", path); + } + else + cprintf(cb, "/"); + break; + case 'w': /* Full Working edit path */ if (clicon_data_get(h, "cli-edit-mode", &path) == 0 && strlen(path)) cprintf(cb, "%s", path); diff --git a/test/test_autocli_editmode.sh b/test/test_autocli_editmode.sh index 025f988f..e51236e1 100755 --- a/test/test_autocli_editmode.sh +++ b/test/test_autocli_editmode.sh @@ -65,7 +65,7 @@ EOF cat < $fspec CLICON_MODE="example"; -CLICON_PROMPT="%U@%H %W> "; +CLICON_PROMPT="%U@%H %w> "; CLICON_PLUGIN="example_cli"; # Autocli syntax tree operations