Pipe function renaming
This commit is contained in:
parent
a773384ccc
commit
e0cbc10fad
3 changed files with 70 additions and 40 deletions
|
|
@ -32,6 +32,7 @@
|
|||
***** END LICENSE BLOCK *****
|
||||
*
|
||||
* @note Paths to bins, such as GREP_BIN, are detected in configure.ac
|
||||
* @note These functions are normally run in a forked sub-process as spawned in cligen_eval()
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
|
@ -132,8 +133,8 @@ pipe_grep_fn(clicon_handle h,
|
|||
char *value = NULL;
|
||||
cg_var *cv;
|
||||
char *str;
|
||||
char *option;
|
||||
char *argname;
|
||||
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));
|
||||
|
|
@ -172,7 +173,7 @@ pipe_wc_fn(clicon_handle h,
|
|||
int retval = -1;
|
||||
cg_var *cv;
|
||||
char *str;
|
||||
char *option;
|
||||
char *option = NULL;
|
||||
|
||||
if (cvec_len(argv) != 1){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <option>", cvec_len(argv));
|
||||
|
|
@ -201,43 +202,74 @@ pipe_tail_fn(clicon_handle h,
|
|||
return pipe_arg_fn(h, TAIL_BIN, "-5", NULL);
|
||||
}
|
||||
|
||||
|
||||
/*! Show as JSON
|
||||
/*! Output pipe translate from xml to other format: json,text,
|
||||
*
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] cvv Vector of cli string and instantiated variables
|
||||
* @param[in] argv String vector of options. Format: <option> <value>
|
||||
* @param[in] argv String vector of show options, format:
|
||||
* <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum), default: xml
|
||||
* <pretty> true|false: pretty-print or not
|
||||
* <prepend> CLI prefix: prepend before cli syntax output
|
||||
* @see cli_show_auto_devs
|
||||
*/
|
||||
int
|
||||
pipe_json_fn(clicon_handle h,
|
||||
pipe_showas_fn(clicon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xt = NULL;
|
||||
|
||||
if (clixon_xml_parse_file(stdin, YB_NONE, NULL, &xt, NULL) < 0)
|
||||
int retval = -1;
|
||||
cxobj *xt = NULL;
|
||||
int argc = 0;
|
||||
enum format_enum format = FORMAT_XML;
|
||||
int ybind = 1;
|
||||
yang_stmt *yspec;
|
||||
int pretty = 1;
|
||||
char *prepend = NULL;
|
||||
|
||||
if (cvec_len(argv) < 1 || cvec_len(argv) > 3){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: <format> [<pretty> [<prepend>]]", cvec_len(argv));
|
||||
goto done;
|
||||
if (clixon_json2file(stdout, xt, 1, cligen_output, 1, 0) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
if (xt)
|
||||
xml_free(xt);
|
||||
return retval;
|
||||
}
|
||||
int
|
||||
pipe_text_fn(clicon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xt = NULL;
|
||||
|
||||
if (clixon_xml_parse_file(stdin, YB_NONE, NULL, &xt, NULL) < 0)
|
||||
goto done;
|
||||
if (clixon_txt2file(stdout, xt, 0, cligen_output, 1, 0) < 0)
|
||||
}
|
||||
if (cvec_len(argv) > argc){
|
||||
fprintf(stderr, "%s formatstr:%s\n", __FUNCTION__, cv_string_get(cvec_i(argv, argc)));
|
||||
if (cli_show_option_format(argv, argc++, &format) < 0)
|
||||
goto done;
|
||||
}
|
||||
if (cvec_len(argv) > argc){
|
||||
if (cli_show_option_bool(argv, argc++, &pretty) < 0)
|
||||
goto done;
|
||||
}
|
||||
if (cvec_len(argv) > argc){
|
||||
prepend = cv_string_get(cvec_i(argv, argc++));
|
||||
}
|
||||
if (ybind){
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
if (clixon_xml_parse_file(stdin, YB_MODULE, yspec, &xt, NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
else if (clixon_xml_parse_file(stdin, YB_NONE, NULL, &xt, NULL) < 0)
|
||||
goto done;
|
||||
fprintf(stderr, "%s format:%d\n", __FUNCTION__, format);
|
||||
switch (format){
|
||||
case FORMAT_XML:
|
||||
if (clixon_xml2file(stdout, xt, 0, pretty, NULL, cligen_output, 1, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_JSON:
|
||||
if (clixon_json2file(stdout, xt, pretty, cligen_output, 1, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_TEXT:
|
||||
if (clixon_txt2file(stdout, xt, 0, cligen_output, 1, 1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_CLI:
|
||||
if (clixon_cli2file(h, stdout, xt, prepend, cligen_output, 1) < 0) /* cli syntax */
|
||||
goto done;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
if (xt)
|
||||
|
|
|
|||
|
|
@ -120,15 +120,14 @@ EOF
|
|||
|
||||
cat <<EOF > $clidir/clipipe.cli
|
||||
CLICON_MODE="|mypipe"; # Must start with |
|
||||
#CLICON_PIPETREE="|mypipe";
|
||||
\| {
|
||||
grep <arg:string>, pipe_grep_fn("-e", "arg");
|
||||
except <arg:string>, pipe_grep_fn("-v", "arg");
|
||||
tail, pipe_tail_fn();
|
||||
count, pipe_wc_fn("-l");
|
||||
showas {
|
||||
json, pipe_json_fn();
|
||||
text, pipe_text_fn();
|
||||
show {
|
||||
json, pipe_showas_fn("json");
|
||||
text, pipe_showas_fn("text");
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
|
@ -177,11 +176,11 @@ expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| tail)" 0 "
|
|||
new "$mode show explicit | count"
|
||||
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| count)" 0 10
|
||||
|
||||
new "$mode show explicit | showas json"
|
||||
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| showas json)" 0 '"name": "x",' --not-- "<name>"
|
||||
new "$mode show explicit | show json"
|
||||
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| show json)" 0 '"name": "x",' --not-- "<name>"
|
||||
|
||||
new "$mode show explicit | showas text"
|
||||
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| showas text)" 0 "name x;" --not-- "<name>"
|
||||
new "$mode show explicit | show text"
|
||||
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| show text)" 0 "parameter x {" --not-- "<name>"
|
||||
|
||||
new "$mode show treeref explicit | grep par"
|
||||
expectpart "$($clixon_cli -1 -m $mode -f $cfg show treeref explicit \| grep par)" 0 "<parameter>" "</parameter>" --not-- "table" "value"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
# Test for RFC8528 YANG Schema Mount
|
||||
# Only if compiled with YANG_SCHEMA_MOUNT
|
||||
# XXX No cli tests
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
|
@ -85,7 +85,6 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS>
|
|||
|
||||
new "check there is statistics from mountpoint"
|
||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><stats xmlns=\"http://clicon.org/lib\"></stats></rpc>" '<module-set><name>mountpoint: /top/mylist\[name="x"\]/root</name><nr>'
|
||||
#"<rpc-reply $DEFAULTNS></rpc-reply>"
|
||||
|
||||
if [ $BE -ne 0 ]; then
|
||||
new "Kill backend"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue