diff --git a/CHANGELOG.md b/CHANGELOG.md index 93d54fae..5d458155 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,8 @@ Developers may need to change their code ### Minor changes +* Change comment character to be active anywhere to beginning of _word_ only. + * See [Change CLIgen comments](https://github.com/clicon/cligen/issues/55) * Improved performance of parsing files as described in [Bytewise read() of files is slow #146](https://github.com/clicon/clixon/issues/146), thanks: @hjelmeland * Added new backend plugin: ca_pre-demon called if backend is daemonized just prior to forking. * Added XPATH functions `position` diff --git a/apps/cli/cli_auto.c b/apps/cli/cli_auto.c index c3a285d0..4b679afa 100644 --- a/apps/cli/cli_auto.c +++ b/apps/cli/cli_auto.c @@ -289,8 +289,7 @@ cli_auto_top(clicon_handle h, cligen_ph_workpoint_set(ph, NULL); /* Store this as edit-mode */ clicon_data_set(h, "cli-edit-mode", ""); - if (clicon_data_cvec_get(h, "cli-edit-cvv") != NULL) - clicon_data_del(h, "cli-edit-cvv"); + clicon_data_cvec_del(h, "cli-edit-cvv"); retval = 0; done: return retval; @@ -617,11 +616,12 @@ cli_auto_sub_enter(clicon_handle h, cvec *cvv, cvec *argv) { - int retval = -1; - char *api_path_fmt; /* Contains wildcards as %.. */ - char *api_path = NULL; + int retval = -1; + char *api_path_fmt; /* Contains wildcards as %.. */ + char *api_path = NULL; char *treename; cvec *cvv1 = NULL; + cvec *cvv2 = NULL; int i; cg_var *cv = NULL; pt_head *ph; @@ -662,23 +662,28 @@ cli_auto_sub_enter(clicon_handle h, } if (api_path_fmt2api_path(api_path_fmt, cvv1, &api_path) < 0) goto done; - /* Set the mode as a static variable to this command */ + /* Assign the variables */ + if ((cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv1)) == NULL) + goto done; + /* Store this as edit-mode */ if (clicon_data_set(h, "cli-edit-mode", api_path) < 0) goto done; - /* Assign the variables */ - if (cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv1) == NULL) + if (clicon_data_cvec_set(h, "cli-edit-cvv", cvv2) < 0) goto done; /* Find current cligen tree */ if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){ - clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename); + clicon_err(OE_PLUGIN, ENOENT, "No such parsetree header: %s", treename); goto done; } /* Find the point in the generated clispec tree where workpoint should be set */ fa.fa_str = api_path_fmt; if (pt_apply(cligen_ph_parsetree_get(ph), cli_auto_findpt, &fa) < 0) goto done; - if (fa.fa_co) - cligen_ph_workpoint_set(ph, fa.fa_co); + if (fa.fa_co == NULL){ + clicon_err(OE_PLUGIN, ENOENT, "No such cligen object found %s", api_path); + goto done; + } + cligen_ph_workpoint_set(ph, fa.fa_co); retval = 0; done: if (api_path) diff --git a/lib/src/clixon_data.c b/lib/src/clixon_data.c index 0f1e6a61..4dd31666 100644 --- a/lib/src/clixon_data.c +++ b/lib/src/clixon_data.c @@ -159,7 +159,7 @@ clicon_data_cvec_get(clicon_handle h, return NULL; } -/*! Set generic cligen varaibel vector (cvv) on the form = where is cvv +/*! Set generic cligen variable vector (cvv) on the form = where is cvv * @param[in] h Clicon handle * @param[in] name Name * @param[in] cvv CLIgen variable vector (cvv) (malloced) @@ -182,7 +182,7 @@ clicon_data_cvec_set(clicon_handle h, return 0; } -/*! Delete generic cligen varaibel vector (cvv) +/*! Delete generic cligen variable vector (cvv) * @param[in] h Clicon handle * @param[in] name Name */ diff --git a/test/test_cli_auto.sh b/test/test_cli_auto.sh index bed3e255..c3d29fa6 100755 --- a/test/test_cli_auto.sh +++ b/test/test_cli_auto.sh @@ -57,7 +57,7 @@ validate("Validate changes"), cli_validate(); commit("Commit the changes"), cli_commit(); quit("Quit"), cli_quit(); show("Show a particular state of the system"){ - configuration("Show configuration"), cli_auto_show("datamodel", "candidate", "xml", false, false);{ + configuration("Show configuration"), cli_auto_show("datamodel", "candidate", "text", true, false);{ xml("Show configuration as XML"), cli_auto_show("datamodel", "candidate", "xml", false, false); cli("Show configuration as CLI commands"), cli_auto_show("datamodel", "candidate", "cli", false, false, "set "); netconf("Show configuration as netconf edit-config operation"), cli_auto_show("datamodel", "candidate", "netconf", false, false); @@ -105,25 +105,25 @@ fi # First go down in structure and show config new "show top tree" -expectpart "$(echo "show config" | $clixon_cli -f $cfg 2>&1)" 0 'a42
$' +expectpart "$(echo "show config xml" | $clixon_cli -f $cfg 2>&1)" 0 'a42
$' cat < $fin up -show config +show config xml EOF new "up show" expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 'a42
$' cat < $fin edit table -show config +show config xml EOF new "edit table; show" expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table>" "a42$" --not-- '' cat < $fin edit table parameter a -show config +show config xml EOF new "edit table parameter a; show" expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/parameter=a/>" "a42" --not-- '
' "" @@ -131,14 +131,14 @@ expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/par cat < $fin edit table edit parameter a -show config +show config xml EOF new "edit table; edit parameter a; show" expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "a42" --not-- '
' "" cat < $fin edit table parameter a value 42 -show config +show config xml EOF new "edit table parameter a value 42; show" expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 --not-- '
' "" "a" "42" @@ -147,7 +147,7 @@ expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 --not-- '
&1)" 0 '
a42
$' @@ -155,7 +155,7 @@ expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '&1)" 0 '
a42
$' @@ -165,7 +165,7 @@ expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '&1)" 0 '
a42
$' @@ -173,7 +173,7 @@ expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '&1)" 0 "/clixon-example:table>" "a42$" --not-- '
' @@ -182,7 +182,7 @@ cat < $fin edit table parameter a up up -show config +show config xml EOF new "edit table parameter a; up up; show" expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '
a42
$' @@ -191,7 +191,7 @@ cat < $fin edit table parameter a up edit parameter a -show config +show config xml EOF new "edit table parameter a; up; edit parameter a; show" expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/parameter=a/>" "a42" --not-- '' "" @@ -199,7 +199,7 @@ expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/par # Create new field b, and remove it cat < $fin edit table parameter b -show config +show config xml EOF new "edit table parameter b; show" expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/parameter=b/>" --not-- "a42" '
' "" @@ -208,7 +208,7 @@ cat < $fin edit table parameter b set value 71 up -show config +show config xml EOF new "set value 71" expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table>" "a42b71" @@ -217,7 +217,7 @@ cat < $fin edit table parameter a top edit table parameter b -show config +show config xml EOF new "edit parameter b show" expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/parameter=b/>" "b71" --not-- "" @@ -225,7 +225,7 @@ expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/par cat < $fin edit table parameter b delete value 17 -show config +show config xml EOF new "delete value 71" expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "b" --not-- "71" @@ -234,7 +234,7 @@ cat < $fin edit table delete parameter b up -show config +show config xml EOF new "delete parameter b" expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '
a42
$' diff --git a/test/test_cli_auto_sub.sh b/test/test_cli_auto_sub.sh index e49d7117..d0f0eecb 100755 --- a/test/test_cli_auto_sub.sh +++ b/test/test_cli_auto_sub.sh @@ -24,6 +24,7 @@ fi cat < $cfg $cfg + ietf-netconf:startup /usr/local/share/clixon $dir $fyang @@ -35,7 +36,7 @@ cat < $cfg VARS /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile - /usr/local/var/$APPNAME + $dir false EOF @@ -58,6 +59,9 @@ module $APPNAME { leaf i{ type string; } + leaf iv{ + type string; + } } } } @@ -66,13 +70,14 @@ EOF cat < $clidir/ex.cli CLICON_MODE="example"; -CLICON_PROMPT="%U@%H> "; +CLICON_PROMPT="%U@%H %W> "; # Manual command form where a sub-mode is created from @datamodel # It gives: cvv eg: # 0 : cmd = parameter 123 # 1 : string = "123" -enter , cli_auto_sub_enter("datamodel", "/example:table/parameter=%s/index=%s/", "x"); +enter0 , cli_auto_sub_enter("datamodel", "/example:table/parameter=%s/"); +enter1 , cli_auto_sub_enter("datamodel", "/example:table/parameter=%s/index=%s/", "p1"); leave, cli_auto_top("datamodel", "candidate"); # Autocli syntax tree operations @@ -87,8 +92,25 @@ delete("Delete a configuration item") { all("Delete whole candidate configuration"), delete_all("candidate"); } show("Show a particular state of the system"){ - configuration("Show configuration"), cli_auto_show("datamodel", "candidate", "text", true, false); + configuration("Show configuration"), cli_auto_show("datamodel", "candidate", "text", true, false);{ + xml("Show configuration as XML"), cli_auto_show("datamodel", "candidate", "xml", false, false); } +} +EOF + +cat < $dir/startup_db + + + + p1 + 42 + + i1 + abc + + +
+
EOF new "test params: -f $cfg" @@ -98,21 +120,37 @@ if [ $BE -ne 0 ]; then if [ $? -ne 0 ]; then err fi - new "start backend -s init -f $cfg" - start_backend -s init -f $cfg + new "start backend -s startup -f $cfg" + start_backend -s startup -f $cfg new "waiting" wait_backend fi cat < $fin -enter a +enter0 p1 # table/parameter=p1 +show config xml leave EOF -new "enter leave" -expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 'enter a' 'leave' +new "enter; show config; leave" +expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 'enter0 p1' 'leave' 'p142i1abc' --not-- '' '' -# XXX much more +cat < $fin +enter0 p1 # table/parameter=p1 +leave +show config xml +EOF +new "enter; leave; show config" +expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 'enter0 p1' 'leave' '
p142i1abc
' + +cat < $fin +enter0 p1 # table/parameter=p1 +set set index i2 iv def +leave +show config xml +EOF +new "set p1 i2" +expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 'p142i1abc
' new "Kill backend" # Check if premature kill