TT#120752 Add 'ngcpcfg edit' to speedup YML editing

Normally it is necessary to press TAB multiple times, e.g:
> vim /etc/ngcp-conf<TAB>/con<TAB>f<TAB>...
For new NGCP users it is even longer.

In the same time we have a nice usability experience for ngcp-ppa,
where users are just pressing "ngcp-ppa<ENTER>1<ENTER>1<ENTER>".

Let's add the same concept here as the order of the main files is static:
> 1) /etc/ngcp-config/config.yml
> 2) /etc/ngcp-config/network.yml
> 3) /etc/ngcp-config/constants.yml

if I need to edit network.yml I will type:
> ngcpc<TAB> e<TAB><ENTER>2<ENTER>

or even:
> ngcpc<TAB> e<TAB>2<ENTER>

Change-Id: Id20fec8c931c15c73a73689a3f8b552a72ef11f7
mr10.0
Alexander Lutay 5 years ago
parent 53f98d540b
commit b821e0052b

@ -25,6 +25,7 @@ scripts/clean usr/share/ngcp-ngcpcfg/scripts/
scripts/commit usr/share/ngcp-ngcpcfg/scripts/
scripts/del usr/share/ngcp-ngcpcfg/scripts/
scripts/diff usr/share/ngcp-ngcpcfg/scripts/
scripts/edit usr/share/ngcp-ngcpcfg/scripts/
scripts/etckeeper usr/share/ngcp-ngcpcfg/scripts/
scripts/get usr/share/ngcp-ngcpcfg/scripts/
scripts/initialise usr/share/ngcp-ngcpcfg/scripts/

@ -70,6 +70,11 @@ _ngcpcfg()
fi
return
;;
edit)
cur=${cur:-/etc/ngcp-config/}
_filedir
return
;;
get)
# XXX - would be nice to get completion based on content of /etc/ngcp-config/*.yml
return

@ -413,6 +413,11 @@ to specify revisions). If the tool doesn't report anything it means that there
are neither any uncommitted changes nor any new or removed files (files which are
not yet (un)registered to the repository).
**edit**::
Helper to edit the ngcpcfg's YML configuration files in a faster way
(it prevents unnecessary <TAB> pressing).
**encrypt**::
Encrypt /etc/ngcp-config and all resulting configuration files with a user

@ -48,6 +48,7 @@ Actions:
commit [<msg>] commit and record changes (without pushing)
del [<opts>] delete YAML option from defined file
diff [<opts>] display pending configuration changes
edit edit YAML configuration files
get <key> print key value from YAML configuration files
help display this help screen and exit
initialise initialise setup (to be executed only once on setup)
@ -141,6 +142,7 @@ case ${1:-} in
init-shared|\
initialise|\
get|\
edit|\
show)
main_action "$@"
;;

@ -0,0 +1,76 @@
#!/bin/bash
# Purpose: edit ngcp-config's configuration YML file
################################################################################
set -e
set -u
# support testsuite
FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}"
HELPER="${HELPER:-/usr/share/ngcp-ngcpcfg/helper/}"
if ! [ -r "${FUNCTIONS}"/main ] ; then
printf "Error: %s/main could not be read. Exiting.\n" "${FUNCTIONS}" >&2
exit 1
fi
if [ -z "${EDITOR:-}" ] ; then
if [ -x "/usr/bin/vim" ]; then
EDITOR="/usr/bin/vim"
else
printf "Error: Missing \$EDITOR environmanent variable. Exiting.\n" >&2
exit 1
fi
fi
# shellcheck disable=SC1090
. "${FUNCTIONS}"/main
# main script
RC=0
file=""
if [ "${#:-}" -ge 1 ] ; then
file=$1
case ${file,,} in
1|config|config.yml)
file="${NGCPCTL_MAIN}/config.yml"
;;
2|network|network.yml)
file="${NGCPCTL_MAIN}/network.yml"
;;
3|constants|constants.yml)
file="${NGCPCTL_MAIN}/constants.yml"
;;
*)
echo "Error: Unknown choise '${file}'. Aborting." >&2
exit 1
;;
esac
else
# Get the list of configs in static order to be constant over the time
# and process the main YML configs first: config.yml network.yml constants.yml
# NOTE: the file are loaded/merged into ngcpcfg in different order!
declare -a CONFIGS
for f in ${NGCPCTL_CONFIG:?} ${NETWORK_CONFIG:?} ${CONSTANTS_CONFIG:?} ${HA_CONFIG:-} ${PAIR_CONFIG:-} ${HOST_CONFIG:-} ${LOCAL_CONFIG:-} "${EXTRA_CONFIG_FILES[@]}" ; do
if [ -r "$f" ] ; then
CONFIGS+=("${f}")
fi
done
select f in "${CONFIGS[@]}" ; do
if [[ -z "${f}" ]]; then
echo "Exit as requested."
exit 0
else
file=$f
break
fi
done
fi
"${EDITOR}" "${file}" || RC=$?
exit "$RC"
## END OF FILE #################################################################
Loading…
Cancel
Save