* 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:
parent
f8ac8cc14b
commit
8d901e1fde
3 changed files with 29 additions and 13 deletions
|
|
@ -655,7 +655,7 @@ clicon_cliread(clicon_handle h,
|
|||
if (clicon_quiet_mode(h))
|
||||
cli_prompt_set(h, "");
|
||||
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);
|
||||
|
||||
if (cliread(cli_cligen(h), stringp) < 0){
|
||||
|
|
@ -724,14 +724,16 @@ cli_set_prompt(clicon_handle h,
|
|||
}
|
||||
|
||||
/*! Format prompt
|
||||
* @param[in] h Clicon handle
|
||||
* @param[out] prompt Prompt string to be written
|
||||
* @param[in] plen Length of prompt string
|
||||
* @param[in] fmt Stdarg fmt string
|
||||
* @param[in] str Stdarg fmt string
|
||||
*/
|
||||
static int
|
||||
prompt_fmt(char *prompt,
|
||||
size_t plen,
|
||||
char *fmt, ...)
|
||||
prompt_fmt(clicon_handle h,
|
||||
char *prompt,
|
||||
size_t plen,
|
||||
char *fmt,...)
|
||||
{
|
||||
va_list ap;
|
||||
char *s = fmt;
|
||||
|
|
@ -740,6 +742,7 @@ prompt_fmt(char *prompt,
|
|||
char *tmp;
|
||||
int ret = -1;
|
||||
cbuf *cb = NULL;
|
||||
char *path = NULL;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
|
|
@ -764,6 +767,13 @@ prompt_fmt(char *prompt,
|
|||
strcpy(tty, "notty");
|
||||
cprintf(cb, "%s", tty);
|
||||
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:
|
||||
cprintf(cb, "%%");
|
||||
cprintf(cb, "%c", *s);
|
||||
|
|
@ -798,11 +808,12 @@ done:
|
|||
* @param[in] fmt Format string
|
||||
*/
|
||||
char *
|
||||
cli_prompt(char *fmt)
|
||||
cli_prompt(clicon_handle h,
|
||||
char *fmt)
|
||||
{
|
||||
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 prompt;
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ char *cli_syntax_mode(clicon_handle h);
|
|||
int cli_syntax_load(clicon_handle h);
|
||||
int cli_handler_err(FILE *fd);
|
||||
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_ptpop(clicon_handle h, char *mode, char *op);
|
||||
|
||||
|
|
|
|||
|
|
@ -493,18 +493,23 @@ module clixon-config {
|
|||
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
|
||||
@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.";
|
||||
}
|
||||
leaf CLICON_CLI_MODEL_TREENAME {
|
||||
type string;
|
||||
default "datamodel";
|
||||
description
|
||||
"If set, CLI specs can reference the
|
||||
model syntax using this reference.
|
||||
"If CLICON_CLI_GENMOEL is set, CLI specs can reference the
|
||||
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();
|
||||
A second tree called eg @datamodelstate is created that
|
||||
also contains state together with config.";
|
||||
show @datamodelshow, cli_show_auto();
|
||||
show state @datamodelstate, cli_show_auto_state();
|
||||
";
|
||||
}
|
||||
leaf CLICON_CLI_GENMODEL_COMPLETION {
|
||||
type int32;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue