From: Frantisek Tobias Date: Fri, 18 Oct 2024 11:26:10 +0000 (+0200) Subject: kresctl: tab-completion: display config keywords in config completion X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=refs%2Fenvironments%2Fdocs-develop-kres-ph09xl%2Fdeployments%2F5365;p=thirdparty%2Fknot-resolver.git kresctl: tab-completion: display config keywords in config completion --- diff --git a/python/knot_resolver/client/command.py b/python/knot_resolver/client/command.py index b0ae38ccd..e0a0c13e9 100644 --- a/python/knot_resolver/client/command.py +++ b/python/knot_resolver/client/command.py @@ -141,7 +141,7 @@ class Command(ABC): @staticmethod def completion(parser: argparse.ArgumentParser, args: Optional[List[str]]) -> CompWords: words: CompWords = get_subparsers_words(parser._actions) # Get subparser words - if args is None or args == ['']: + if args is None or args == [""]: return words subparsers = parser._subparsers @@ -153,13 +153,12 @@ class Command(ABC): uarg = args[i] subparser = get_subparser_by_name(uarg, subparsers._actions) # pylint: disable=W0212 - # print(f"uarg: {uarg}, {args}, {words}\n") if subparser: try: cmd = get_subparser_command(subparser) subparser_args = args[i + 1 :] words = cmd.completion(subparser, subparser_args) - except: + except ValueError: return get_subparsers_words(subparser._actions) break diff --git a/python/knot_resolver/client/commands/completion.py b/python/knot_resolver/client/commands/completion.py index cffd7e0df..b7a804d89 100644 --- a/python/knot_resolver/client/commands/completion.py +++ b/python/knot_resolver/client/commands/completion.py @@ -2,16 +2,7 @@ import argparse from enum import Enum from typing import List, Tuple, Type -from knot_resolver.client.command import ( - Command, - CommandArgs, - CompWords, - get_subparser_by_name, - get_subparser_command, - get_subparsers_words, - register_command, -) -from knot_resolver.client.commands.config import ConfigCommand +from knot_resolver.client.command import Command, CommandArgs, register_command class Shells(Enum): diff --git a/python/knot_resolver/client/commands/config.py b/python/knot_resolver/client/commands/config.py index 8523cf2bf..5d0b5c74b 100644 --- a/python/knot_resolver/client/commands/config.py +++ b/python/knot_resolver/client/commands/config.py @@ -3,10 +3,17 @@ import sys from enum import Enum from typing import Any, Dict, List, Literal, Optional, Tuple, Type -from knot_resolver.client.command import Command, CommandArgs, CompWords, register_command, get_subparser_by_name, get_subparsers_words +from knot_resolver.client.command import ( + Command, + CommandArgs, + CompWords, + get_subparser_by_name, + get_subparsers_words, + register_command, +) +from knot_resolver.datamodel import KresConfig from knot_resolver.utils.modeling.parsing import DataFormat, parse_json, try_to_parse from knot_resolver.utils.requests import request -from knot_resolver.datamodel import KresConfig class Operations(Enum): @@ -228,7 +235,6 @@ class ConfigCommand(Command): return words - def run(self, args: CommandArgs) -> None: if not self.operation: args.subparser.print_help() diff --git a/python/knot_resolver/constants.py b/python/knot_resolver/constants.py index 567be9f7f..2acb86603 100644 --- a/python/knot_resolver/constants.py +++ b/python/knot_resolver/constants.py @@ -1,14 +1,14 @@ from pathlib import Path VERSION = "6.0.8" -USER = "ftobias" -GROUP = "ftobias" +USER = "knot-resolver" +GROUP = "knot-resolver" # dirs paths -RUN_DIR = Path("/home/ftobias/knot_projects/knot-resolver/.install_dev/run/knot-resolver") -ETC_DIR = Path("/home/ftobias/knot_projects/knot-resolver/.install_dev/etc/knot-resolver") -SBIN_DIR = Path("/home/ftobias/knot_projects/knot-resolver/.install_dev/sbin") -CACHE_DIR = Path("/home/ftobias/knot_projects/knot-resolver/.install_dev/var/cache/knot-resolver") +RUN_DIR = Path("/run/knot-resolver") +ETC_DIR = Path("/etc/knot-resolver") +SBIN_DIR = Path("/usr/sbin") +CACHE_DIR = Path("/var/cache/knot-resolver") # files paths CONFIG_FILE = ETC_DIR / "config.yaml"