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 *****
|
***** END LICENSE BLOCK *****
|
||||||
*
|
*
|
||||||
* @note Paths to bins, such as GREP_BIN, are detected in configure.ac
|
* @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
|
#ifdef HAVE_CONFIG_H
|
||||||
|
|
@ -132,8 +133,8 @@ pipe_grep_fn(clicon_handle h,
|
||||||
char *value = NULL;
|
char *value = NULL;
|
||||||
cg_var *cv;
|
cg_var *cv;
|
||||||
char *str;
|
char *str;
|
||||||
char *option;
|
char *option = NULL;
|
||||||
char *argname;
|
char *argname = NULL;
|
||||||
|
|
||||||
if (cvec_len(argv) != 2){
|
if (cvec_len(argv) != 2){
|
||||||
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <option> <argname>", cvec_len(argv));
|
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;
|
int retval = -1;
|
||||||
cg_var *cv;
|
cg_var *cv;
|
||||||
char *str;
|
char *str;
|
||||||
char *option;
|
char *option = NULL;
|
||||||
|
|
||||||
if (cvec_len(argv) != 1){
|
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: <option>", cvec_len(argv));
|
||||||
|
|
@ -201,43 +202,74 @@ pipe_tail_fn(clicon_handle h,
|
||||||
return pipe_arg_fn(h, TAIL_BIN, "-5", NULL);
|
return pipe_arg_fn(h, TAIL_BIN, "-5", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Output pipe translate from xml to other format: json,text,
|
||||||
/*! Show as JSON
|
|
||||||
*
|
*
|
||||||
* @param[in] h Clicon handle
|
* @param[in] h Clicon handle
|
||||||
* @param[in] cvv Vector of cli string and instantiated variables
|
* @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
|
int
|
||||||
pipe_json_fn(clicon_handle h,
|
pipe_showas_fn(clicon_handle h,
|
||||||
cvec *cvv,
|
cvec *cvv,
|
||||||
cvec *argv)
|
cvec *argv)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
cxobj *xt = NULL;
|
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 (clixon_xml_parse_file(stdin, YB_NONE, NULL, &xt, NULL) < 0)
|
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;
|
goto done;
|
||||||
if (clixon_json2file(stdout, xt, 1, cligen_output, 1, 0) < 0)
|
}
|
||||||
goto done;
|
if (cvec_len(argv) > argc){
|
||||||
retval = 0;
|
fprintf(stderr, "%s formatstr:%s\n", __FUNCTION__, cv_string_get(cvec_i(argv, argc)));
|
||||||
done:
|
if (cli_show_option_format(argv, argc++, &format) < 0)
|
||||||
if (xt)
|
goto done;
|
||||||
xml_free(xt);
|
}
|
||||||
return retval;
|
if (cvec_len(argv) > argc){
|
||||||
}
|
if (cli_show_option_bool(argv, argc++, &pretty) < 0)
|
||||||
int
|
goto done;
|
||||||
pipe_text_fn(clicon_handle h,
|
}
|
||||||
cvec *cvv,
|
if (cvec_len(argv) > argc){
|
||||||
cvec *argv)
|
prepend = cv_string_get(cvec_i(argv, argc++));
|
||||||
{
|
}
|
||||||
int retval = -1;
|
if (ybind){
|
||||||
cxobj *xt = NULL;
|
yspec = clicon_dbspec_yang(h);
|
||||||
|
if (clixon_xml_parse_file(stdin, YB_MODULE, yspec, &xt, NULL) < 0)
|
||||||
if (clixon_xml_parse_file(stdin, YB_NONE, NULL, &xt, NULL) < 0)
|
goto done;
|
||||||
goto done;
|
}
|
||||||
if (clixon_txt2file(stdout, xt, 0, cligen_output, 1, 0) < 0)
|
else if (clixon_xml_parse_file(stdin, YB_NONE, NULL, &xt, NULL) < 0)
|
||||||
goto done;
|
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;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
if (xt)
|
if (xt)
|
||||||
|
|
|
||||||
|
|
@ -120,15 +120,14 @@ EOF
|
||||||
|
|
||||||
cat <<EOF > $clidir/clipipe.cli
|
cat <<EOF > $clidir/clipipe.cli
|
||||||
CLICON_MODE="|mypipe"; # Must start with |
|
CLICON_MODE="|mypipe"; # Must start with |
|
||||||
#CLICON_PIPETREE="|mypipe";
|
|
||||||
\| {
|
\| {
|
||||||
grep <arg:string>, pipe_grep_fn("-e", "arg");
|
grep <arg:string>, pipe_grep_fn("-e", "arg");
|
||||||
except <arg:string>, pipe_grep_fn("-v", "arg");
|
except <arg:string>, pipe_grep_fn("-v", "arg");
|
||||||
tail, pipe_tail_fn();
|
tail, pipe_tail_fn();
|
||||||
count, pipe_wc_fn("-l");
|
count, pipe_wc_fn("-l");
|
||||||
showas {
|
show {
|
||||||
json, pipe_json_fn();
|
json, pipe_showas_fn("json");
|
||||||
text, pipe_text_fn();
|
text, pipe_showas_fn("text");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
@ -177,11 +176,11 @@ expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| tail)" 0 "
|
||||||
new "$mode show explicit | count"
|
new "$mode show explicit | count"
|
||||||
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| count)" 0 10
|
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| count)" 0 10
|
||||||
|
|
||||||
new "$mode show explicit | showas json"
|
new "$mode show explicit | show json"
|
||||||
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| showas json)" 0 '"name": "x",' --not-- "<name>"
|
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| show json)" 0 '"name": "x",' --not-- "<name>"
|
||||||
|
|
||||||
new "$mode show explicit | showas text"
|
new "$mode show explicit | show text"
|
||||||
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| showas text)" 0 "name x;" --not-- "<name>"
|
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"
|
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"
|
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
|
#!/usr/bin/env bash
|
||||||
# Test for RFC8528 YANG Schema Mount
|
# 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)
|
# Magic line must be first in script (see README.md)
|
||||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
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"
|
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>'
|
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
|
if [ $BE -ne 0 ]; then
|
||||||
new "Kill backend"
|
new "Kill backend"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue