CLI pipe changes: added arg to tail, exit on error.

This commit is contained in:
Olof hagsand 2023-08-15 20:37:30 +02:00
parent 7352894c7e
commit 2bcd429bee
4 changed files with 44 additions and 9 deletions

View file

@ -44,6 +44,11 @@
## 6.4.0
Expected: October 2023
### C/CLI-API changes on existing features
Developers may need to change their code
* CLI pipe function: added arg to `pipe_tail_fn()`
### Minor features
* Removed sending restconf config inline using -R when CLICON_BACKEND_RESTCONF_PROCESS=true

View file

@ -1145,8 +1145,8 @@ yang2cli_uses(clicon_handle h,
if (ys_grouping_resolve(ys, prefix, id, &ygrouping) < 0)
goto done;
if (ygrouping == NULL){
fprintf(stderr, "%s grouping %s not found\n", __FUNCTION__, id);
goto ok;
clicon_err(OE_YANG, 0, "grouping %s not found in \n", yang_argument_get(ys));
goto done;
}
if ((cbtree = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");

View file

@ -176,7 +176,7 @@ pipe_wc_fn(clicon_handle h,
char *option = NULL;
if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <option>", cvec_len(argv));
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <NUM>", cvec_len(argv));
goto done;
}
if ((cv = cvec_i(argv, 0)) != NULL &&
@ -199,7 +199,34 @@ pipe_tail_fn(clicon_handle h,
cvec *cvv,
cvec *argv)
{
return pipe_arg_fn(h, TAIL_BIN, "-5", NULL);
int retval = -1;
char *value = NULL;
cg_var *cv;
char *str;
char *option = NULL;
char *argname = NULL;
if (cvec_len(argv) != 2){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <option> <argname>", cvec_len(argv));
goto done;
}
if ((cv = cvec_i(argv, 0)) != NULL &&
(str = cv_string_get(cv)) != NULL &&
strlen(str))
option = str;
if ((cv = cvec_i(argv, 1)) != NULL &&
(str = cv_string_get(cv)) != NULL &&
strlen(str))
argname = str;
if (argname && strlen(argname)){
if ((cv = cvec_find_var(cvv, argname)) != NULL &&
(str = cv_string_get(cv)) != NULL &&
strlen(str))
value = str;
}
return pipe_arg_fn(h, TAIL_BIN, option, value);
done:
return retval;
}
/*! Output pipe translate from xml to other format: json,text,

View file

@ -128,7 +128,7 @@ CLICON_MODE="|mypipe"; # Must start with |
\| {
grep <arg:string>, pipe_grep_fn("-e", "arg");
except <arg:string>, pipe_grep_fn("-v", "arg");
tail, pipe_tail_fn();
tail <arg:string>, pipe_tail_fn("-n", "arg");
count, pipe_wc_fn("-l");
show {
json, pipe_showas_fn("json");
@ -175,8 +175,11 @@ expectpart "$($clixon_cli -1 -m $mode -f $cfg show implicit config \| grep par 2
new "$mode show explicit | grep par"
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| grep par)" 0 "<parameter>" "</parameter>" --not-- "table" "value"
new "$mode show explicit | tail"
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| tail)" 0 "<name>y</name>" --not-- "<name>x</name>"
new "$mode show explicit | grep table|name"
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| grep 'table\\\|name')" 0 "<table xmlns=\"urn:example:clixon\">" "<name>x</name>" "<name>y</name>" "</table>" --not-- "parameter" "value"
new "$mode show explicit | tail 5"
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| tail 5)" 0 "<name>y</name>" --not-- "<name>x</name>"
new "$mode show explicit | count"
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| count)" 0 10