-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* CLI history: [Preserve CLI command history across sessions. The up/…
…down arrows](#79) * The design is similar to bash history: * The CLI loads/saves its complete history to a file on entry and exit, respectively * The size (number of lines) of the file is the same as the history in memory * Only the latest session dumping its history will survive (bash merges multiple session history). * Tilde-expansion is supported * Files not found or without appropriate access will not cause an exit but will be logged at debug level * New config options: CLICON_CLI_HIST_FILE with default value `~/.clixon_cli_history` * New config options: CLICON_CLI_HIST_SIZE with default value 300.
- Loading branch information
1 parent
5602d3e
commit b03f833
Showing
8 changed files
with
255 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/bin/bash | ||
# Basic CLI history test | ||
|
||
# Magic line must be first in script (see README.md) | ||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi | ||
|
||
APPNAME=example | ||
|
||
# include err() and new() functions and creates $dir | ||
|
||
cfg=$dir/conf_yang.xml | ||
histfile=$dir/histfile | ||
|
||
# Use yang in example | ||
|
||
cat <<EOF > $cfg | ||
<clixon-config xmlns="http://clicon.org/config"> | ||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE> | ||
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR> | ||
<CLICON_YANG_DIR>$IETFRFC</CLICON_YANG_DIR> | ||
<CLICON_YANG_MODULE_MAIN>clixon-example</CLICON_YANG_MODULE_MAIN> | ||
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR> | ||
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR> | ||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR> | ||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE> | ||
<CLICON_CLI_HIST_FILE>$histfile</CLICON_CLI_HIST_FILE> | ||
<CLICON_CLI_HIST_SIZE>10</CLICON_CLI_HIST_SIZE> | ||
<CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK> | ||
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE> | ||
<CLICON_CLI_GENMODEL_COMPLETION>1</CLICON_CLI_GENMODEL_COMPLETION> | ||
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR> | ||
<CLICON_XMLDB_PLUGIN>/usr/local/lib/xmldb/text.so</CLICON_XMLDB_PLUGIN> | ||
</clixon-config> | ||
EOF | ||
|
||
cat <<EOF > $histfile | ||
first line | ||
EOF | ||
|
||
# NOTE Backend is not really use here | ||
new "test params: -f $cfg" | ||
if [ $BE -ne 0 ]; then | ||
new "kill old backend" | ||
sudo clixon_backend -z -f $cfg | ||
if [ $? -ne 0 ]; then | ||
err | ||
fi | ||
new "start backend -s init -f $cfg" | ||
start_backend -s init -f $cfg | ||
|
||
new "waiting" | ||
sleep $RCWAIT | ||
fi | ||
|
||
new "cli read and add entry to existing history" | ||
expecteof "$clixon_cli -f $cfg" 0 "example 42" "data" | ||
|
||
new "Check histfile exists" | ||
if [ ! -f $histfile ]; then | ||
err "$histfile" "not found" | ||
fi | ||
|
||
new "Check it has two entries" | ||
lines=$(cat $histfile | wc -l) | ||
if [ $lines -ne 2 ]; then | ||
err "Line:$lines" "2" | ||
fi | ||
|
||
new "check it contains first line" | ||
nr=$(grep -c "example 42" $histfile) | ||
if [ $nr -ne 1 ]; then | ||
err "Contains: example 42" "1" | ||
fi | ||
|
||
new "Check it contains example 42" | ||
nr=$(grep -c "example 42" $histfile) | ||
if [ $nr -ne 1 ]; then | ||
err "Contains: example 42" "1" | ||
fi | ||
|
||
new "cli add entry and create newhist file" | ||
expecteof "$clixon_cli -f $cfg -o CLICON_CLI_HIST_FILE=$dir/newhist" 0 "example 43" "data" | ||
|
||
new "Check newhist exists" | ||
if [ ! -f $dir/newhist ]; then | ||
err "$dir/newhist" "not found" | ||
fi | ||
|
||
new "check it contains example 43" | ||
nr=$(grep -c "example 43" $dir/newhist) | ||
if [ $nr -ne 1 ]; then | ||
err "Contains: example 43" "1" | ||
fi | ||
|
||
if [ $BE -eq 0 ]; then | ||
exit # BE | ||
fi | ||
|
||
new "Kill backend" | ||
# Check if premature kill | ||
pid=`pgrep -u root -f clixon_backend` | ||
if [ -z "$pid" ]; then | ||
err "backend already dead" | ||
fi | ||
# kill backend | ||
stop_backend -f $cfg | ||
|
||
|
||
rm -rf $dir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters