mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-03 14:07:24 +00:00
cli: Fix outdated kata-runtime bash completion
adapt to the latest kata-runtime version Fixes: #2254 Signed-off-by: Binbin Zhang <binbin36520@gmail.com>
This commit is contained in:
parent
3c9170ea0d
commit
f5172d1c36
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
#
|
#
|
||||||
# Copyright (c) 2018 Intel Corporation
|
# Copyright (c) 2018 Intel Corporation
|
||||||
#
|
#
|
||||||
@ -53,39 +53,6 @@ _kata_subcmd_seen()
|
|||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
# Return 0 if the specified sub-command requires the name of an
|
|
||||||
# *existing* container, else 1.
|
|
||||||
_kata_subcmd_needs_existing_container()
|
|
||||||
{
|
|
||||||
local subcmd="$1"
|
|
||||||
local cmd
|
|
||||||
|
|
||||||
for cmd in \
|
|
||||||
'kata-check' \
|
|
||||||
'kata-env' \
|
|
||||||
'check' \
|
|
||||||
'env' \
|
|
||||||
'create' \
|
|
||||||
'help' \
|
|
||||||
'list' \
|
|
||||||
'version'; do
|
|
||||||
[ "$cmd" = "$subcmd" ] && return 1
|
|
||||||
done
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
# Returns a list of container names
|
|
||||||
_kata_get_containers()
|
|
||||||
{
|
|
||||||
# Commands that manipulate containers need root privileges.
|
|
||||||
# If the user isn't running as root, don't attempt to obtain a list
|
|
||||||
# as it will result in an error.
|
|
||||||
[ $(id -u) -eq 0 ] || return
|
|
||||||
|
|
||||||
"$_kataruntime" list --quiet
|
|
||||||
}
|
|
||||||
|
|
||||||
_kata_bash_autocomplete() {
|
_kata_bash_autocomplete() {
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
|
|
||||||
@ -104,19 +71,9 @@ _kata_bash_autocomplete() {
|
|||||||
local subcmd_seen=$(_kata_subcmd_seen)
|
local subcmd_seen=$(_kata_subcmd_seen)
|
||||||
|
|
||||||
if [ -n "$subcmd_seen" ]; then
|
if [ -n "$subcmd_seen" ]; then
|
||||||
_kata_subcmd_needs_existing_container "$subcmd_seen"
|
|
||||||
local container_cmd=$?
|
|
||||||
|
|
||||||
if [ -n "$cur" ]; then
|
if [ -n "$cur" ]; then
|
||||||
# Complete with local options and maybe container names
|
|
||||||
opts=$(_kata_get_subcmd_options "$subcmd_seen")
|
|
||||||
[ $container_cmd -eq 0 ] && opts="$opts $(_kata_get_containers)"
|
|
||||||
elif [[ "${cur}" == -* ]]; then
|
|
||||||
# Complete with local options
|
# Complete with local options
|
||||||
opts=$(_kata_get_subcmd_options "$subcmd_seen")
|
opts=$(_kata_get_subcmd_options "$subcmd_seen")
|
||||||
else
|
|
||||||
# Potentially complete with container names
|
|
||||||
[ $container_cmd -eq 0 ] && opts="$(_kata_get_containers)"
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ -n "$cur" ]; then
|
if [ -n "$cur" ]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user