summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2025-12-17 13:13:25 -0600
committerJohn Estabrook <jestabro@vyos.io>2025-12-19 08:06:54 -0600
commit573cc710c340eb48bf1db7af6caccde1b1f5ca31 (patch)
treef6e508c136eb1d5a7fbbd94e8d88205e82af0998
parent7c0b17cf52153edfa6b2e36be4cd50829e30d197 (diff)
downloadvyatta-cfg-573cc710c340eb48bf1db7af6caccde1b1f5ca31.tar.gz
vyatta-cfg-573cc710c340eb48bf1db7af6caccde1b1f5ca31.zip
T8061: use vyconf compatible calls for completion data
Use alternatives for validateTmplPath, getNodeType, getCompletionEnv.
-rw-r--r--etc/bash_completion.d/vyatta-cfg122
-rw-r--r--functions/interpreter/vyatta-cfg-run118
2 files changed, 174 insertions, 66 deletions
diff --git a/etc/bash_completion.d/vyatta-cfg b/etc/bash_completion.d/vyatta-cfg
index 9bd1eb3..bbb6d12 100644
--- a/etc/bash_completion.d/vyatta-cfg
+++ b/etc/bash_completion.d/vyatta-cfg
@@ -489,7 +489,11 @@ get_help_text ()
vyatta_help_text+="\\x20\\x20"
else
if [[ $print_node_type -ne 0 ]]; then
- local nodeType=$(cli-shell-api getNodeType ${editlvl} ${api_args[@]:1:$[${comp_cword}-1]} "${_get_help_text_items[idx]}")
+ if test -f "/var/run/vyconf_backend"; then
+ local nodeType=$(${vyconf_bin_dir}/vyconf_cli_compat getNodeType ${editlvl} ${api_args[@]:1:$[${comp_cword}-1]} "${_get_help_text_items[idx]}")
+ else
+ local nodeType=$(cli-shell-api getNodeType ${editlvl} ${api_args[@]:1:$[${comp_cword}-1]} "${_get_help_text_items[idx]}")
+ fi
case "$nodeType" in
tag) vyatta_help_text+="+> " ;;
non-leaf) vyatta_help_text+=" > " ;;
@@ -777,7 +781,11 @@ vyatta_config_expand_compwords ()
else
path=( "${expanded_api_args[@]}" "$arg" )
fi
- vyatta_cli_shell_api getCompletionEnv "${path[@]}"
+ if test -f "/var/run/vyconf_backend"; then
+ vyos_cli_shell_api getCompletionEnv "${path[@]}"
+ else
+ vyatta_cli_shell_api getCompletionEnv "${path[@]}"
+ fi
if [[ "${#_cli_shell_api_comp_values[@]}" == "1" ]]; then
if [[ "$_cli_shell_api_last_comp_val" == 'true' ]]; then
arg=$arg
@@ -804,7 +812,11 @@ vyatta_config_invalid_comp ()
local path=''
local opath=''
local failed=false
- local validate="cli-shell-api validateTmplPath -- $editlvl"
+ if test -f "/var/run/vyconf_backend"; then
+ local validate="${vyconf_bin_dir}/vyconf_cli_compat validateTmplPath $editlvl"
+ else
+ local validate="cli-shell-api validateTmplPath -- $editlvl"
+ fi
for elem in "${expanded_api_args[@]:1}"; do
if [[ -z "$elem" ]]; then
continue
@@ -827,34 +839,66 @@ vyatta_config_invalid_comp ()
else
path="$path $arg"
fi
- if ! cli-shell-api validateTmplPath -- ${editlvl} ${path}; then
- _cli_shell_api_comp_values=()
- vyatta_cli_shell_api getCompletionEnv $cmd ${path}
- if [[ "${#_cli_shell_api_comp_values[@]}" != "1"
- && "${#_cli_shell_api_comp_values[@]}" != "0" ]]; then
- local -a _get_help_text_items=( "${_cli_shell_api_hitems[@]}" )
- local -a _get_help_text_helps=( "${_cli_shell_api_hstrs[@]}" )
- local vyatta_help_text=''
- if [[ $opath == '' ]]; then
- echo -ne "\n\n Configuration path: [$arg] is ambiguous\n"
+ if test -f "/var/run/vyconf_backend"; then
+ if ! ${vyconf_bin_dir}/vyconf_cli_compat validateTmplPath ${editlvl} ${path}; then
+ _cli_shell_api_comp_values=()
+ vyos_cli_shell_api getCompletionEnv $cmd ${path}
+ if [[ "${#_cli_shell_api_comp_values[@]}" != "1"
+ && "${#_cli_shell_api_comp_values[@]}" != "0" ]]; then
+ local -a _get_help_text_items=( "${_cli_shell_api_hitems[@]}" )
+ local -a _get_help_text_helps=( "${_cli_shell_api_hstrs[@]}" )
+ local vyatta_help_text=''
+ if [[ $opath == '' ]]; then
+ echo -ne "\n\n Configuration path: [$arg] is ambiguous\n"
+ else
+ echo -ne "\n\n Configuration path: $opath [$arg] is ambiguous\n"
+ fi
+ get_help_text 0
+ echo -ne "$vyatta_help_text\n" | sed 's/^P/ P/'
+ failed=true
+ break
else
- echo -ne "\n\n Configuration path: $opath [$arg] is ambiguous\n"
+ if [[ $opath == '' ]]; then
+ echo -ne "\n\n Configuration path: [$arg] is not valid"
+ else
+ echo -ne "\n\n Configuration path: $opath [$arg] is not valid"
+ fi
+ failed=true
+ break
fi
- get_help_text 0
- echo -ne "$vyatta_help_text\n" | sed 's/^P/ P/'
- failed=true
- break
else
- if [[ $opath == '' ]]; then
- echo -ne "\n\n Configuration path: [$arg] is not valid"
+ opath=$path
+ fi
+ else
+ if ! cli-shell-api validateTmplPath -- ${editlvl} ${path}; then
+ _cli_shell_api_comp_values=()
+ vyatta_cli_shell_api getCompletionEnv $cmd ${path}
+ if [[ "${#_cli_shell_api_comp_values[@]}" != "1"
+ && "${#_cli_shell_api_comp_values[@]}" != "0" ]]; then
+ local -a _get_help_text_items=( "${_cli_shell_api_hitems[@]}" )
+ local -a _get_help_text_helps=( "${_cli_shell_api_hstrs[@]}" )
+ local vyatta_help_text=''
+ if [[ $opath == '' ]]; then
+ echo -ne "\n\n Configuration path: [$arg] is ambiguous\n"
+ else
+ echo -ne "\n\n Configuration path: $opath [$arg] is ambiguous\n"
+ fi
+ get_help_text 0
+ echo -ne "$vyatta_help_text\n" | sed 's/^P/ P/'
+ failed=true
+ break
else
- echo -ne "\n\n Configuration path: $opath [$arg] is not valid"
+ if [[ $opath == '' ]]; then
+ echo -ne "\n\n Configuration path: [$arg] is not valid"
+ else
+ echo -ne "\n\n Configuration path: $opath [$arg] is not valid"
+ fi
+ failed=true
+ break
fi
- failed=true
- break
+ else
+ opath=$path
fi
- else
- opath=$path
fi
done
fi
@@ -1009,7 +1053,11 @@ vyatta_config_complete ()
# only do this for the second comp
local nodeType="non-leaf"
if [[ ${#api_args[@]} -gt 2 ]]; then
- nodeType=$(cli-shell-api getNodeType ${editlvl} ${api_args[@]:1:$[${comp_cword}-1]})
+ if test -f "/var/run/vyconf_backend"; then
+ nodeType=$(${vyconf_bin_dir}/vyconf_cli_compat getNodeType ${editlvl} ${api_args[@]:1:$[${comp_cword}-1]})
+ else
+ nodeType=$(cli-shell-api getNodeType ${editlvl} ${api_args[@]:1:$[${comp_cword}-1]})
+ fi
fi
# Change the api arguments when we are dealing with a non last word
@@ -1024,12 +1072,22 @@ vyatta_config_complete ()
api_args=( "${api_args[@]:0:$comp_cword}" "" )
fi
fi
- if ! vyatta_cli_shell_api getCompletionEnv "${api_args[@]}"; then
- # invalid completion
- vyatta_config_invalid_comp "${expanded_api_args[@]}"
- COMPREPLY=( "" " " )
- eval $restore_shopts
- return
+ if test -f "/var/run/vyconf_backend"; then
+ if ! vyos_cli_shell_api getCompletionEnv "${api_args[@]}"; then
+ # invalid completion
+ vyatta_config_invalid_comp "${expanded_api_args[@]}"
+ COMPREPLY=( "" " " )
+ eval $restore_shopts
+ return
+ fi
+ else
+ if ! vyatta_cli_shell_api getCompletionEnv "${api_args[@]}"; then
+ # invalid completion
+ vyatta_config_invalid_comp "${expanded_api_args[@]}"
+ COMPREPLY=( "" " " )
+ eval $restore_shopts
+ return
+ fi
fi
vyatta_cfg_comp_help=$_cli_shell_api_comp_help
if [[ $exists_only == 1 ]] &&
diff --git a/functions/interpreter/vyatta-cfg-run b/functions/interpreter/vyatta-cfg-run
index 605559c..5583d02 100644
--- a/functions/interpreter/vyatta-cfg-run
+++ b/functions/interpreter/vyatta-cfg-run
@@ -475,39 +475,70 @@ vyatta_cfg_validate_cmd ()
local path=''
local opath=''
for arg in "${expanded_api_args[@]:1}"; do
- if [[ "$path" == '' ]]; then
+ if [[ "$path" == '' ]]; then
path="$arg"
else
path="$path $arg"
- fi
- if ! cli-shell-api validateTmplPath -- ${editlvl} ${path}; then
- _cli_shell_api_comp_values=()
- vyatta_cli_shell_api getCompletionEnv $cmd ${path}
- if [[ "${#_cli_shell_api_comp_values[@]}" != "1"
- && "${#_cli_shell_api_comp_values[@]}" != "0" ]]; then
- local -a _get_help_text_items=( "${_cli_shell_api_hitems[@]}" )
- local -a _get_help_text_helps=( "${_cli_shell_api_hstrs[@]}" )
- local vyatta_help_text=''
- if [[ $opath == '' ]]; then
- echo -ne "\n Configuration path: [$arg] is ambiguous\n" >&2
+ fi
+ if test -f "/var/run/vyconf_backend"; then
+ if ! ${vyconf_bin_dir}/vyconf_cli_compat validateTmplPath ${editlvl} ${path}; then
+ _cli_shell_api_comp_values=()
+ vyos_cli_shell_api getCompletionEnv $cmd ${path}
+ if [[ "${#_cli_shell_api_comp_values[@]}" != "1"
+ && "${#_cli_shell_api_comp_values[@]}" != "0" ]]; then
+ local -a _get_help_text_items=( "${_cli_shell_api_hitems[@]}" )
+ local -a _get_help_text_helps=( "${_cli_shell_api_hstrs[@]}" )
+ local vyatta_help_text=''
+ if [[ $opath == '' ]]; then
+ echo -ne "\n Configuration path: [$arg] is ambiguous\n" >&2
+ else
+ echo -ne "\n Configuration path: $opath [$arg] is ambiguous\n" >&2
+ fi
+ get_help_text
+ echo -e "$vyatta_help_text\n" | sed 's/^P/ P/'
+ echo -e " ${cmd^} failed\n"
+ break
else
- echo -ne "\n Configuration path: $opath [$arg] is ambiguous\n" >&2
+ if [[ $opath == '' ]]; then
+ echo -ne "\n Configuration path: [$arg] is not valid\n ${cmd^} failed\n\n" >&2
+ else
+ echo -ne "\n Configuration path: $opath [$arg] is not valid\n ${cmd^} failed\n\n" >&2
+ fi
+ break
fi
- get_help_text
- echo -e "$vyatta_help_text\n" | sed 's/^P/ P/'
- echo -e " ${cmd^} failed\n"
- break
else
- if [[ $opath == '' ]]; then
- echo -ne "\n Configuration path: [$arg] is not valid\n ${cmd^} failed\n\n" >&2
+ opath=$path
+ fi
+ else
+ if ! cli-shell-api validateTmplPath -- ${editlvl} ${path}; then
+ _cli_shell_api_comp_values=()
+ vyatta_cli_shell_api getCompletionEnv $cmd ${path}
+ if [[ "${#_cli_shell_api_comp_values[@]}" != "1"
+ && "${#_cli_shell_api_comp_values[@]}" != "0" ]]; then
+ local -a _get_help_text_items=( "${_cli_shell_api_hitems[@]}" )
+ local -a _get_help_text_helps=( "${_cli_shell_api_hstrs[@]}" )
+ local vyatta_help_text=''
+ if [[ $opath == '' ]]; then
+ echo -ne "\n Configuration path: [$arg] is ambiguous\n" >&2
+ else
+ echo -ne "\n Configuration path: $opath [$arg] is ambiguous\n" >&2
+ fi
+ get_help_text
+ echo -e "$vyatta_help_text\n" | sed 's/^P/ P/'
+ echo -e " ${cmd^} failed\n"
+ break
else
- echo -ne "\n Configuration path: $opath [$arg] is not valid\n ${cmd^} failed\n\n" >&2
+ if [[ $opath == '' ]]; then
+ echo -ne "\n Configuration path: [$arg] is not valid\n ${cmd^} failed\n\n" >&2
+ else
+ echo -ne "\n Configuration path: $opath [$arg] is not valid\n ${cmd^} failed\n\n" >&2
+ fi
+ break
fi
- break
+ else
+ opath=$path
fi
- else
- opath=$path
- fi
+ fi
done
}
@@ -604,21 +635,40 @@ vyatta_cfg_cmd ()
local editlvl=$(cli-shell-api getEditLevelStr)
fi
vyatta_config_expand_compwords "${args[@]}"
- if [[ "${expanded_api_args[@]:$[${#expanded_api_args[@]}-1]}" == "-all" ]] &&
- [[ "${expanded_api_args[0]}" == "show" ]]; then
- if [[ $[${#expanded_api_args[@]}-2] -eq 0 ]]; then
- vyatta_cfg_cmd_run "${expanded_api_args[@]}"
- elif cli-shell-api validateTmplPath -- ${editlvl[*]} \
- "${expanded_api_args[@]:1:$[${#expanded_api_args[@]}-2]}"; then
+ if test -f "/var/run/vyconf_backend"; then
+ if [[ "${expanded_api_args[@]:$[${#expanded_api_args[@]}-1]}" == "-all" ]] &&
+ [[ "${expanded_api_args[0]}" == "show" ]]; then
+ if [[ $[${#expanded_api_args[@]}-2] -eq 0 ]]; then
+ vyatta_cfg_cmd_run "${expanded_api_args[@]}"
+ elif ${vyconf_bin_dir}/vyconf_cli_compat validateTmplPath ${editlvl[*]} \
+ "${expanded_api_args[@]:1:$[${#expanded_api_args[@]}-2]}"; then
+ vyatta_cfg_cmd_run "${expanded_api_args[@]}"
+ else
+ vyatta_cfg_validate_cmd "${expanded_api_args[@]}"
+ fi
+ elif ${vyconf_bin_dir}/vyconf_cli_compat validateTmplPath ${editlvl[*]} "${expanded_api_args[@]:1}"; then
vyatta_cfg_cmd_run "${expanded_api_args[@]}"
else
+ # find broken portion of command
vyatta_cfg_validate_cmd "${expanded_api_args[@]}"
fi
- elif cli-shell-api validateTmplPath -- ${editlvl[*]} "${expanded_api_args[@]:1}"; then
- vyatta_cfg_cmd_run "${expanded_api_args[@]}"
else
- # find broken portion of command
- vyatta_cfg_validate_cmd "${expanded_api_args[@]}"
+ if [[ "${expanded_api_args[@]:$[${#expanded_api_args[@]}-1]}" == "-all" ]] &&
+ [[ "${expanded_api_args[0]}" == "show" ]]; then
+ if [[ $[${#expanded_api_args[@]}-2] -eq 0 ]]; then
+ vyatta_cfg_cmd_run "${expanded_api_args[@]}"
+ elif cli-shell-api validateTmplPath -- ${editlvl[*]} \
+ "${expanded_api_args[@]:1:$[${#expanded_api_args[@]}-2]}"; then
+ vyatta_cfg_cmd_run "${expanded_api_args[@]}"
+ else
+ vyatta_cfg_validate_cmd "${expanded_api_args[@]}"
+ fi
+ elif cli-shell-api validateTmplPath -- ${editlvl[*]} "${expanded_api_args[@]:1}"; then
+ vyatta_cfg_cmd_run "${expanded_api_args[@]}"
+ else
+ # find broken portion of command
+ vyatta_cfg_validate_cmd "${expanded_api_args[@]}"
+ fi
fi
}
### Top level wrappers ###