if subparsers:
words = get_subparsers_words(subparsers._actions)
- for i in range(len(args)):
+ i = 0
+ while i < len(args):
uarg = args[i]
subparser = get_subparser_by_name(uarg, subparsers._actions) # pylint: disable=W0212
if subparser:
- try:
- cmd = get_subparser_command(subparser)
- subparser_args = args[i + 1 :]
- words = cmd.completion(subparser, subparser_args)
- except ValueError:
- return get_subparsers_words(subparser._actions)
-
- break
+ cmd = get_subparser_command(subparser)
+ subparser_args = args[i + 1 :]
+ words = cmd.completion(subparser, subparser_args)
+
elif uarg in ["-s", "--socket", "-c", "--config"]:
# Skip next argument if a known flag is detected
i += 1
# next(uargs, None)
- continue
- elif uarg in ["--bash", "--space"]:
+ # elif uarg in ["--bash", "--space"]:
# Continue if the argument is a valid subparser
- continue
+ i += 1
return words
CompWords,
get_subparser_by_name,
get_subparsers_words,
+ get_subparser_command,
register_command,
)
from knot_resolver.datamodel import KresConfig
return words
+def get_config_path_options():
+ return _properties_words(KresConfig.json_schema()["properties"])
+
+
def _path_comp_words(node: str, nodes: List[str], props: Dict[str, Any]) -> CompWords:
i = nodes.index(node)
ln = len(nodes[i:])
nargs="?",
)
- # GET & SET config options
- prop_words = _properties_words(KresConfig.json_schema()["properties"])
- for prop_key in prop_words:
- get.add_argument(
- prop_key,
- help=prop_words[prop_key],
- type=str,
- nargs="?",
- )
-
- set.add_argument(
- prop_key,
- help=prop_words[prop_key],
- action="store",
- type=str,
- nargs="?",
- )
-
# DELETE operation
delete = config_subparsers.add_parser(
"delete", help="Delete given configuration property or list item at the given index."
if args is None or len(args) <= 1:
return Command.completion(parser, args)
- words: CompWords = get_subparsers_words(parser._actions)
+ words: CompWords = get_subparsers_words(parser._actions) # Get subparser words
+
subparsers = parser._subparsers
+ schema_props: Dict[str, Any] = KresConfig.json_schema()["properties"]
if subparsers:
+ words = get_subparsers_words(subparsers._actions)
+
for i in range(len(args)):
uarg = args[i]
+ if uarg == "conf_get_path_subst" and \
+ (uarg == args[-2] or (uarg == args[-3] and args[-2] not in schema_props)):
+ return get_config_path_options()
+
subparser = get_subparser_by_name(uarg, subparsers._actions) # pylint: disable=W0212
- if subparser is not None:
- subparser_words = get_subparsers_words(subparser._actions)
- words = dict()
- for action in subparser._actions:
- if action.dest not in subparser_words:
- subparser_words[action.dest] = action.help or None
-
- words.update(subparser_words)
-
- subparsers = subparser._subparsers
- if not subparsers:
- break
- else:
- break
-
- # for arg in args:
- # if arg in words:
- # continue
- # elif arg.startswith("-"):
- # return words
- # elif arg == args[-1]:
- # config_path = arg[1:].split("/") if arg.startswith("/") else arg.split("/")
- # schema_props: Dict[str, Any] = KresConfig.json_schema()["properties"]
- # return _path_comp_words(config_path[0], config_path, schema_props)
- # else:
- # break
+
+ if subparser:
+ try:
+ cmd = get_subparser_command(subparser)
+ subparser_args = args[i + 1 :]
+ words = cmd.completion(subparser, subparser_args)
+ except ValueError:
+ subparser_words = get_subparsers_words(subparser._actions)
+
+ words = dict()
+ for action in subparser._actions:
+ if action.dest not in subparser_words:
+ subparser_words[action.dest] = action.help or None
+
+ words.update(subparser_words)
return words
+
def run(self, args: CommandArgs) -> None:
if not self.operation:
args.subparser.print_help()
new_words[count]="$WORD"
((count++))
else
+ new_words[count]=" "
+ ((count++))
_kresctl_skip_next=1
fi
else
COMPREPLY=()
local cur opts cmp_words
- cur="${COMP_WORDS[COMP_CWORD]}"
+ for (( i=2; i<${#COMP_WORDS[@]}; i++ )); do
+ if [[ "${COMP_WORDS[i-2]}" == "config" ]] &&
+ ([[ "${COMP_WORDS[i]}" == "-p" ]] || [[ "${COMP_WORDS[i]}" == "--path" ]]); then
+ COMP_WORDS[i]="conf_get_path_subst"
+ break
+ fi
+ done
+ cur="${COMP_WORDS[COMP_CWORD]}"
cmp_words=($(_kresctl_filter_switches))
# check if there is a word is empty
# no word to complete, return all posible options
opts=$(kresctl completion --bash --space "${cmp_words[@]}")
else
- opts=$(kresctl completion --bash "${cmp_words[@]}")
+ opts=$(kresctl completion --bash --space "${cmp_words[@]}")
fi
# if there is no completion from kresctl