diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c index bc457702..e10e2063 100644 --- a/apps/cli/cli_show.c +++ b/apps/cli/cli_show.c @@ -1371,6 +1371,7 @@ cli_pagination(clixon_handle h, cxobj **xvec = NULL; size_t xlen; int locked = 0; + int argc = 0; if (cvec_len(argv) != 5){ clixon_err(OE_PLUGIN, 0, "Expected usage: "); @@ -1380,14 +1381,12 @@ cli_pagination(clixon_handle h, if ((cv = cvec_find(cvv, "xpath")) != NULL) xpath = cv_string_get(cv); else - xpath = cvec_i_str(argv, 0); - prefix = cvec_i_str(argv, 1); - namespace = cvec_i_str(argv, 2); - str = cv_string_get(cvec_i(argv, 3)); /* Fourthformat: output format */ - if ((int)(format = format_str2int(str)) < 0){ - clixon_err(OE_PLUGIN, 0, "Not valid format: %s", str); + xpath = cvec_i_str(argv, argc); + argc++; + prefix = cvec_i_str(argv, argc++); + namespace = cvec_i_str(argv, argc++); + if (cli_show_option_format(h, argv, argc++, &format) < 0) goto done; - } if ((str = cv_string_get(cvec_i(argv, 4))) != NULL){ if (parse_uint32(str, &limit, NULL) < 1){ clixon_err(OE_UNIX, errno, "error parsing limit:%s", str); diff --git a/example/main/Makefile.in b/example/main/Makefile.in index 29e6c192..844e4da0 100644 --- a/example/main/Makefile.in +++ b/example/main/Makefile.in @@ -103,7 +103,8 @@ all: $(PLUGINS) .c.o: $(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $< -CLISPECS = $(APPNAME)_cli.cli +CLISPECS = $(APPNAME)_cli.cli +CLISPECS += $(APPNAME)_pipe.cli YANGSPECS = clixon-example@2022-11-01.yang diff --git a/example/main/example_cli.cli b/example/main/example_cli.cli index 185ace15..93c8579c 100644 --- a/example/main/example_cli.cli +++ b/example/main/example_cli.cli @@ -94,13 +94,9 @@ show("Show a particular state of the system"){ xml("Show comparison in xml"), compare_dbs("running", "candidate", "xml"); text("Show comparison in text"), compare_dbs("running", "candidate", "text"); } - pagination("Show list pagination") xpath("Show configuration") ("XPATH expression"){ - xml, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "xml", "10"); - cli, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "cli", "10"); - text, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "text", "10"); - json, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "json", "10"); - } + pagination("Show list pagination") xpath("Show configuration") ("XPATH expression"), cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "default", "10"); configuration("Show configuration"), cli_show_auto_mode("candidate", "default", true, false, "explicit", "set ");{ + @|example_pipe, cli_show_auto_mode("candidate", "xml", true, false, "explicit"); default("With-default mode"){ report-all, cli_show_auto_mode("candidate", "default", true, false, "report-all"); trim, cli_show_auto_mode("candidate", "default", true, false, "trim"); @@ -111,16 +107,15 @@ show("Show a particular state of the system"){ } } state("Show configuration and state"), cli_show_auto_mode("running", "default", true, true); { - xml("Show configuration and state as XML"), cli_show_auto_mode("running", "default", true, true);{ - default("With-default mode"){ - report-all, cli_show_auto_mode("running", "default", true, true, "report-all"); - trim, cli_show_auto_mode("running", "default", true, true, "trim"); - explicit, cli_show_auto_mode("running", "default", true, true, "explicit"); - report-all-tagged, cli_show_auto_mode("running", "default", true, true, "report-all-tagged"); - report-all-tagged-default, cli_show_auto_mode("running", "default", true, true, "report-all-tagged-default"); - report-all-tagged-strip, cli_show_auto_mode("running", "default", true, true, "report-all-tagged-strip"); - } - } + @|example_pipe, cli_show_auto_mode("running", "xml", true, true); + default("With-default mode"){ + report-all, cli_show_auto_mode("running", "default", true, true, "report-all"); + trim, cli_show_auto_mode("running", "default", true, true, "trim"); + explicit, cli_show_auto_mode("running", "default", true, true, "explicit"); + report-all-tagged, cli_show_auto_mode("running", "default", true, true, "report-all-tagged"); + report-all-tagged-default, cli_show_auto_mode("running", "default", true, true, "report-all-tagged-default"); + report-all-tagged-strip, cli_show_auto_mode("running", "default", true, true, "report-all-tagged-strip"); + } } yang("Show yang specs"), show_yang(); { clixon-example("Show clixon-example yang spec"), show_yang("clixon-example"); diff --git a/example/main/example_pipe.cli b/example/main/example_pipe.cli new file mode 100644 index 00000000..7ea49e85 --- /dev/null +++ b/example/main/example_pipe.cli @@ -0,0 +1,47 @@ +# ***** BEGIN LICENSE BLOCK ***** +# +# Copyright (C) 2024 Olof Hagsand +# +# This file is part of CLIXON +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Alternatively, the contents of this file may be used under the terms of +# the GNU General Public License Version 3 or later (the "GPL"), +# in which case the provisions of the GPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of the GPL, and not to allow others to +# use your version of this file under the terms of Apache License version 2, +# indicate your decision by deleting the provisions above and replace them with +# the notice and other provisions required by the GPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the Apache License version 2 or the GPL. +# +# ***** END LICENSE BLOCK ***** + +# Clixon pipe example specification + +CLICON_MODE="|example_pipe"; # Must start with | +\| { + grep("Search for pattern") , pipe_grep_fn("-e", "arg"); + except("Inverted search") , pipe_grep_fn("-v", "arg"); + tail("Output last part") , pipe_tail_fn("-n", "arg"); + count("Line count"), pipe_wc_fn("-l"); + show("Show other format") { + cli("set Input cli syntax"), pipe_showas_fn("cli", true, "set "); + xml("XML"), pipe_showas_fn("xml", true); + json("JSON"), pipe_showas_fn("json"); + text("Text curly braces"), pipe_showas_fn("text"); + } +# save("Save configuration to file") ("Filename (local filename)"), save_config_file("candidate","filename", "xml"); # XXX +} diff --git a/test/test_pagination_config.sh b/test/test_pagination_config.sh index b128cefe..b282422c 100755 --- a/test/test_pagination_config.sh +++ b/test/test_pagination_config.sh @@ -50,6 +50,7 @@ cat < $cfg true $APPNAME /usr/local/lib/$APPNAME/cli + cli /usr/local/lib/$APPNAME/clispec $validatexml diff --git a/test/test_pagination_expect.exp b/test/test_pagination_expect.exp index 1720cc5a..2d0a4a0b 100755 --- a/test/test_pagination_expect.exp +++ b/test/test_pagination_expect.exp @@ -28,7 +28,7 @@ set timeout 15 spawn {*}$clixon_cli -f $cfg -send "show pagination xpath $xpath cli\n" +send "show pagination xpath $xpath\n" expect { timeout { send_user "\n$line1 not received.\n"; exit 1} diff --git a/test/test_pagination_state.sh b/test/test_pagination_state.sh index ff06a3d5..6fd6d15a 100755 --- a/test/test_pagination_state.sh +++ b/test/test_pagination_state.sh @@ -45,6 +45,7 @@ cat < $cfg true $APPNAME /usr/local/lib/$APPNAME/cli + cli /usr/local/lib/$APPNAME/clispec $validatexml diff --git a/test/test_perf_state.sh b/test/test_perf_state.sh index a66fa17a..fe75a5fb 100755 --- a/test/test_perf_state.sh +++ b/test/test_perf_state.sh @@ -179,7 +179,7 @@ done } 2>&1 | awk '/real/ {print $2}' # CLI get cat <> $fin edit interfaces a foo b interface e1 -show state xml +show state EOF new "cli get test single req" expectpart "$($clixon_cli -F $fin -f $cfg)" 0 "e1" "eth" "up$" @@ -187,7 +187,7 @@ expectpart "$($clixon_cli -F $fin -f $cfg)" 0 "e1" "eth /dev/null + $clixon_cli -1 -f $cfg show state interfaces a b interface e$rnd > /dev/null done } 2>&1 | awk '/real/ {print $2}' # Get config in one large get @@ -199,7 +199,7 @@ new "restconf get large config" $TIMEFN curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/example:interfaces/a=foo/b 2>&1 | awk '/real/ {print $2}' new "cli get large config" -$TIMEFN $clixon_cli -1f $cfg show state xml interfaces a foo b 2>&1 | awk '/real/ {print $2}' +$TIMEFN $clixon_cli -1f $cfg show state interfaces a foo b 2>&1 | awk '/real/ {print $2}' # mem test needs sleep here new "wait restconf"