* Extended CLI_PROMPT syntax with %W as working path in tree, which more concretely is a path to the current position in a syntax tree in the autocli.

* Comments on clixon-config.yang
This commit is contained in:
Olof hagsand 2020-10-12 11:19:43 +02:00
parent f8ac8cc14b
commit 8d901e1fde
3 changed files with 29 additions and 13 deletions

View file

@ -655,7 +655,7 @@ clicon_cliread(clicon_handle h,
if (clicon_quiet_mode(h)) if (clicon_quiet_mode(h))
cli_prompt_set(h, ""); cli_prompt_set(h, "");
else else
cli_prompt_set(h, cli_prompt(pfmt ? pfmt : mode->csm_prompt)); cli_prompt_set(h, cli_prompt(h, pfmt ? pfmt : mode->csm_prompt));
cligen_tree_active_set(cli_cligen(h), mode->csm_name); cligen_tree_active_set(cli_cligen(h), mode->csm_name);
if (cliread(cli_cligen(h), stringp) < 0){ if (cliread(cli_cligen(h), stringp) < 0){
@ -724,14 +724,16 @@ cli_set_prompt(clicon_handle h,
} }
/*! Format prompt /*! Format prompt
* @param[in] h Clicon handle
* @param[out] prompt Prompt string to be written * @param[out] prompt Prompt string to be written
* @param[in] plen Length of prompt string * @param[in] plen Length of prompt string
* @param[in] fmt Stdarg fmt string * @param[in] str Stdarg fmt string
*/ */
static int static int
prompt_fmt(char *prompt, prompt_fmt(clicon_handle h,
char *prompt,
size_t plen, size_t plen,
char *fmt, ...) char *fmt,...)
{ {
va_list ap; va_list ap;
char *s = fmt; char *s = fmt;
@ -740,6 +742,7 @@ prompt_fmt(char *prompt,
char *tmp; char *tmp;
int ret = -1; int ret = -1;
cbuf *cb = NULL; cbuf *cb = NULL;
char *path = NULL;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new"); clicon_err(OE_XML, errno, "cbuf_new");
@ -764,6 +767,13 @@ prompt_fmt(char *prompt,
strcpy(tty, "notty"); strcpy(tty, "notty");
cprintf(cb, "%s", tty); cprintf(cb, "%s", tty);
break; break;
case 'W': /* working edit path */
if (clicon_data_get(h, "cli-edit-mode", &path) == 0 &&
strlen(path))
cprintf(cb, "%s", path);
else
cprintf(cb, "/");
break;
default: default:
cprintf(cb, "%%"); cprintf(cb, "%%");
cprintf(cb, "%c", *s); cprintf(cb, "%c", *s);
@ -798,11 +808,12 @@ done:
* @param[in] fmt Format string * @param[in] fmt Format string
*/ */
char * char *
cli_prompt(char *fmt) cli_prompt(clicon_handle h,
char *fmt)
{ {
static char prompt[CLI_PROMPT_LEN]; static char prompt[CLI_PROMPT_LEN];
if (prompt_fmt(prompt, sizeof(prompt), fmt) < 0) if (prompt_fmt(h, prompt, sizeof(prompt), fmt) < 0)
return CLI_DEFAULT_PROMPT; return CLI_DEFAULT_PROMPT;
return prompt; return prompt;

View file

@ -53,7 +53,7 @@ char *cli_syntax_mode(clicon_handle h);
int cli_syntax_load(clicon_handle h); int cli_syntax_load(clicon_handle h);
int cli_handler_err(FILE *fd); int cli_handler_err(FILE *fd);
int cli_set_prompt(clicon_handle h, const char *mode, const char *prompt); int cli_set_prompt(clicon_handle h, const char *mode, const char *prompt);
char *cli_prompt(char *fmt); char *cli_prompt(clicon_handle h, char *fmt);
int cli_ptpush(clicon_handle h, char *mode, char *string, char *op); int cli_ptpush(clicon_handle h, char *mode, char *string, char *op);
int cli_ptpop(clicon_handle h, char *mode, char *op); int cli_ptpop(clicon_handle h, char *mode, char *op);

View file

@ -493,18 +493,23 @@ module clixon-config {
1: Generate a CLI specification for CLI completion of all loaded Yang modules. 1: Generate a CLI specification for CLI completion of all loaded Yang modules.
This CLI tree can be accessed in CLI-spec files using the tree reference syntax (eg This CLI tree can be accessed in CLI-spec files using the tree reference syntax (eg
@datamodel). @datamodel).
2: Same including state syntax in a tree called @datamodelstate. 2: Same including state syntax in a tree called @datamodelstate and @datamodelshow
See also CLICON_CLI_MODEL_TREENAME."; See also CLICON_CLI_MODEL_TREENAME.";
} }
leaf CLICON_CLI_MODEL_TREENAME { leaf CLICON_CLI_MODEL_TREENAME {
type string; type string;
default "datamodel"; default "datamodel";
description description
"If set, CLI specs can reference the "If CLICON_CLI_GENMOEL is set, CLI specs can reference the
model syntax using this reference. model syntax using a model tree set by this option.
Three trees are generated with this name as a base, (assuming base is datamodel):
- @datamodel - a clispec for navigating in editing a configuration (set/merge/delete)
- @datamodelshow - a clispec for navigating in showing a configuration
- @datamodelstate - a clispec for navigating in showing a configuration WITH state
Example: set @datamodel, cli_set(); Example: set @datamodel, cli_set();
A second tree called eg @datamodelstate is created that show @datamodelshow, cli_show_auto();
also contains state together with config."; show state @datamodelstate, cli_show_auto_state();
";
} }
leaf CLICON_CLI_GENMODEL_COMPLETION { leaf CLICON_CLI_GENMODEL_COMPLETION {
type int32; type int32;