Example cli pipe grep command quotes vertical bar for OR function
This commit is contained in:
parent
1698c6717e
commit
4e79ac43fb
3 changed files with 26 additions and 4 deletions
|
|
@ -51,6 +51,7 @@ Developers may need to change their code
|
||||||
|
|
||||||
### Minor features
|
### Minor features
|
||||||
|
|
||||||
|
* Example cli pipe grep command quotes vertical bar for OR function
|
||||||
* New command-line option for dumping configuration options for all clixon applications after load
|
* New command-line option for dumping configuration options for all clixon applications after load
|
||||||
* Syntax is `-C <format>`
|
* Syntax is `-C <format>`
|
||||||
* Example: `clixon_backend -1C json`
|
* Example: `clixon_backend -1C json`
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,11 @@
|
||||||
|
|
||||||
***** END LICENSE BLOCK *****
|
***** END LICENSE BLOCK *****
|
||||||
*
|
*
|
||||||
|
* Example cli pipe output functions.
|
||||||
* @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()
|
* @note These functions are normally run in a forked sub-process as spawned in cligen_eval()
|
||||||
|
* A developer should probably revise these functions, since they are primarily intended for testing
|
||||||
|
* of the pipe functionality
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
|
|
@ -123,6 +126,7 @@ pipe_arg_fn(clicon_handle h,
|
||||||
* @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 options. Format: <option> <value>
|
||||||
|
* @note Any vertical bar (|] in the patterns field is quoted for OR function
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
pipe_grep_fn(clicon_handle h,
|
pipe_grep_fn(clicon_handle h,
|
||||||
|
|
@ -130,11 +134,14 @@ pipe_grep_fn(clicon_handle h,
|
||||||
cvec *argv)
|
cvec *argv)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
char *value = NULL;
|
char *pattern = NULL;
|
||||||
cg_var *cv;
|
cg_var *cv;
|
||||||
char *str;
|
char *str;
|
||||||
char *option = NULL;
|
char *option = NULL;
|
||||||
char *argname = NULL;
|
char *argname = NULL;
|
||||||
|
cbuf *cb = NULL;
|
||||||
|
int i;
|
||||||
|
char c;
|
||||||
|
|
||||||
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));
|
||||||
|
|
@ -148,14 +155,28 @@ pipe_grep_fn(clicon_handle h,
|
||||||
(str = cv_string_get(cv)) != NULL &&
|
(str = cv_string_get(cv)) != NULL &&
|
||||||
strlen(str))
|
strlen(str))
|
||||||
argname = str;
|
argname = str;
|
||||||
|
if ((cb = cbuf_new()) == NULL){
|
||||||
|
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
if (argname && strlen(argname)){
|
if (argname && strlen(argname)){
|
||||||
if ((cv = cvec_find_var(cvv, argname)) != NULL &&
|
if ((cv = cvec_find_var(cvv, argname)) != NULL &&
|
||||||
(str = cv_string_get(cv)) != NULL &&
|
(str = cv_string_get(cv)) != NULL &&
|
||||||
strlen(str))
|
strlen(str))
|
||||||
value = str;
|
pattern = str;
|
||||||
}
|
}
|
||||||
retval = pipe_arg_fn(h, GREP_BIN, option, value);
|
/* quote | in pattern into cbuf */
|
||||||
|
for (i=0; i<strlen(pattern); i++){
|
||||||
|
c = pattern[i];
|
||||||
|
if (c == '|')
|
||||||
|
cprintf(cb, "\\|");
|
||||||
|
else
|
||||||
|
cprintf(cb, "%c", c);
|
||||||
|
}
|
||||||
|
retval = pipe_arg_fn(h, GREP_BIN, option, cbuf_get(cb));
|
||||||
done:
|
done:
|
||||||
|
if (cb)
|
||||||
|
cbuf_free(cb);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,7 @@ 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"
|
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| grep par)" 0 "<parameter>" "</parameter>" --not-- "table" "value"
|
||||||
|
|
||||||
new "$mode show explicit | grep table|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"
|
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"
|
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>"
|
expectpart "$($clixon_cli -1 -m $mode -f $cfg show explicit config \| tail 5)" 0 "<name>y</name>" --not-- "<name>x</name>"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue