diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c index 0ce29730..62421190 100644 --- a/apps/cli/cli_show.c +++ b/apps/cli/cli_show.c @@ -865,8 +865,8 @@ cli_show_version(clicon_handle h, cvec *vars, cvec *argv) { - fprintf(stdout, "Clixon: %s\n", CLIXON_VERSION_STRING); - fprintf(stdout, "CLIgen: %s\n", CLIGEN_VERSION); + cligen_output(stdout, "Clixon: %s\n", CLIXON_VERSION_STRING); + cligen_output(stdout, "CLIgen: %s\n", CLIGEN_VERSION); return 0; } diff --git a/test/test_cli_pipe.sh b/test/test_cli_pipe.sh index c0c100d3..2f82c58b 100755 --- a/test/test_cli_pipe.sh +++ b/test/test_cli_pipe.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash # CLIgen output pipe functions # Note, | must be escaped as \| otherwise shell's pipe is used (w possibly same result) -# XXX Autocli does not work # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi @@ -115,12 +114,11 @@ EOF cat < $clidir/treeref.cli CLICON_MODE="treeref"; -CLICON_PIPETREE="|mypipe"; +CLICON_PIPETREE="|mypipe"; # implicit implicit("Show configuration"), cli_show_auto_mode("candidate", "xml", true, false); explicit("Show configuration"), cli_show_auto_mode("candidate", "xml", true, false);{ @|mypipe, cli_show_auto_mode("candidate", "xml", true, false); } - EOF cat < $clidir/clipipe.cli diff --git a/test/test_cli_pipe_multi.sh b/test/test_cli_pipe_multi.sh new file mode 100755 index 00000000..9561da79 --- /dev/null +++ b/test/test_cli_pipe_multi.sh @@ -0,0 +1,178 @@ +#!/usr/bin/env bash +# CLIgen output pipe functions with multiple trees and specs +# 1. Multiple pipe files: pipe_common + pipe_show where the latter is a superset +# 2. Implicit pipe and explicit in same file where explicit overrides +# 3. Multiple trees where sub-tree (@datamodel) inherits from treeref + +# Magic line must be first in script (see README.md) +s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi + +APPNAME=example + +# include err() and new() functions and creates $dir + +cfg=$dir/conf_yang.xml +fyang=$dir/clixon-example.yang +clidir=$dir/clidir +fin=$dir/in + +if [ ! -d $clidir ]; then + mkdir $clidir +fi + +cat < $cfg + + $cfg + ${YANG_INSTALLDIR} + $fyang + /usr/local/lib/$APPNAME/backend + $clidir + /usr/local/lib/$APPNAME/cli + $APPNAME + /usr/local/var/$APPNAME/$APPNAME.sock + /usr/local/var/$APPNAME/$APPNAME.pidfile + /usr/local/var/$APPNAME + +EOF + +cat < $fyang +module clixon-example{ + yang-version 1.1; + namespace "urn:example:clixon"; + prefix ex; + /* Generic config data */ + container table{ + list parameter{ + key name; + leaf name{ + type string; + } + leaf value{ + type string; + } + } + } +} +EOF + +cat < $clidir/example.cli +CLICON_MODE="example"; +CLICON_PROMPT="%U@%H %W> "; +CLICON_PIPETREE="|common"; # implicit + +# Autocli syntax tree operations +edit @datamodel, cli_auto_edit("datamodel"); +up, cli_auto_up("datamodel"); +top, cli_auto_top("datamodel"); +set @datamodel, cli_auto_set(); +delete("Delete a configuration item") { + @datamodel, cli_auto_del(); + all("Delete whole candidate configuration"), delete_all("candidate"); +} +commit("Commit the changes"), cli_commit(); +show("Show a particular state of the system"){ + version("Show version"), cli_show_version("candidate", "text", "/"); + configuration("Show configuration"), cli_show_auto_mode("candidate", "xml", true, false);{ + @|show, cli_show_auto_mode("candidate", "xml", true, false); + @datamodelshow, cli_show_auto("candidate", "xml", true, false, "report-all"); + } + autocli("Generated tree") @datamodelshow, cli_show_auto("candidate", "xml", true, false, "report-all"); +} +EOF + +cat < $clidir/common.cli +CLICON_MODE="|common:|show"; +\| { + grep , pipe_grep_fn("-e", "arg"); + except , pipe_grep_fn("-v", "arg"); + tail , pipe_tail_fn("-n", "arg"); + count, pipe_wc_fn("-l"); +} +EOF + +cat < $clidir/show.cli +CLICON_MODE="|show"; # Must start with | +\| { + showas { + xml, pipe_showas_fn("xml"); + json, pipe_showas_fn("json"); + text, pipe_showas_fn("text"); + } +} +EOF + +new "test params: -f $cfg" +if [ $BE -ne 0 ]; then + new "kill old backend" + sudo clixon_backend -z -f $cfg + if [ $? -ne 0 ]; then + err + fi + new "start backend -s init -f $cfg" + start_backend -s init -f $cfg +fi + +new "wait backend" +wait_backend + +new "Add entry x" +expectpart "$($clixon_cli -1 -f $cfg set table parameter x value a)" 0 "^$" + +new "Add entry y" +expectpart "$($clixon_cli -1 -f $cfg set table parameter y value b)" 0 "^$" + +new "Commit" +expectpart "$($clixon_cli -1 -f $cfg commit)" 0 "^$" + +# 1. Multiple pipe files: pipe_common + pipe_show where the latter is a superset +new "multiple files: show menu contains common items" +echo "$clixon_cli -1 -f $cfg show config \| count" +expectpart "$($clixon_cli -1 -f $cfg show config \| count)" 0 10 + +# 2. Implicit pipe and explicit in same file where explicit overrides +new "Implicit default command" +expectpart "$(echo "show version \| ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 count --not-- showas + +new "Explicit override" +expectpart "$(echo "show configuration \| ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 count showas + +# 3. Multiple trees where sub-tree (@datamodel) inherits from treeref +new "sub-tree default implicit" +expectpart "$(echo "set table \| ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 count --not-- showas + +new "sub-tree explicit" +expectpart "$(echo "show config table \| ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 count showas + +# History error: second command affected by first +# show configuration | count is OK +cat < $fin +show configuration table | count +set table | showas xml +EOF +new "Explicit followed by implicit" +expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "set table | showas xml\": Unknown command" --not-- "a" + +cat < $fin +set table parameter y value nisse | count +show configuration table | showas xml +EOF +new "Implicit followed by explicit" +expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "a" --not-- "Unknown command" + +if [ $BE -ne 0 ]; then + new "Kill backend" + # Check if premature kill + pid=$(pgrep -u root -f clixon_backend) + if [ -z "$pid" ]; then + err "backend already dead" + fi + # kill backend + stop_backend -f $cfg +fi + +rm -rf $dir + +unset mode + +new "endtest" +endtest diff --git a/yang/clixon/clixon-autocli@2023-09-01.yang b/yang/clixon/clixon-autocli@2023-09-01.yang index ebb14b25..229c1259 100644 --- a/yang/clixon/clixon-autocli@2023-09-01.yang +++ b/yang/clixon/clixon-autocli@2023-09-01.yang @@ -43,7 +43,7 @@ module clixon-autocli{ revision 2023-09-01 { description - "Added argument to alias + "Added argument to alias extension Released in Clixon 6.3"; } revision 2023-05-01 {