]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
kresctl: tab-completion: fix liter complaints
authorFrantisek Tobias <frantisek.tobias@nic.cz>
Fri, 15 Nov 2024 09:50:47 +0000 (10:50 +0100)
committerFrantisek Tobias <frantisek.tobias@nic.cz>
Fri, 15 Nov 2024 11:35:55 +0000 (12:35 +0100)
python/knot_resolver/client/command.py
python/knot_resolver/client/commands/completion.py
python/knot_resolver/client/commands/config.py

index 6ffefa6630f95c02af2bc47f411840be69c9decc..dbd99227a3f0f6dcd728e6dfec49d9db16a16967 100644 (file)
@@ -140,37 +140,37 @@ class Command(ABC):
         if args is None or len(args) == 0:
             return {}
 
-        words: CompWords = get_subparsers_words(parser._actions)
+        words: CompWords = get_subparsers_words(parser._actions)  # pylint: disable=protected-access
 
-        subparsers = parser._subparsers
+        subparsers = parser._subparsers  # pylint: disable=protected-access
 
         if subparsers:
             while curr_index < len(args):
                 uarg = args[curr_index]
-                subparser = get_subparser_by_name(uarg, subparsers._actions)  # pylint: disable=W0212
+                subpar = get_subparser_by_name(uarg, subparsers._actions)  # pylint: disable=W0212
 
                 curr_index += 1
-                if subparser and curr_index < len(args):
-                    cmd = get_subparser_command(subparser)
-                    if cmd is 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)
+                if subpar:
+                    cmd = get_subparser_command(subpar)
+                    if cmd is not None:
+                        if len(args) > curr_index:
+                            words = cmd.completion(subpar, args, curr_index)
 
-                    elif len(args) > curr_index:
-                        new_words = cmd.completion(subparser, args, curr_index)
+                        return words
 
-                        if new_words is None:
-                            words = new_words
+                    subpar_actions = subpar._actions  # pylint: disable=protected-access
+                    subparser_words = get_subparsers_words(subpar_actions)
+                    words = {}
+                    for action in subpar_actions:
+                        if action.dest not in subparser_words:
+                            subparser_words[action.dest] = action.help or None
 
-                    # return words
+                    words.update(subparser_words)
+                    return words
 
                 elif uarg in ["-s", "--socket", "-c", "--config"]:
-                    # folowing word shall not be a kresctl command, switch to path completion
-                    if uarg == args[-1] or uarg == args[-2]:
+                    # following word shall not be a kresctl command, switch to path completion
+                    if uarg in (args[-1], args[-2]):
                         words = {}
                     curr_index += 1
 
index 58601404c0215a88a5696ec5904a5c4e1aef2e93..5b65212d2058f5cc56a74fe4c0ec53184ea29559 100644 (file)
@@ -42,12 +42,7 @@ class CompletionCommand(Command):
         shells.add_argument("--bash", action="store_const", dest=shells_dest, const=Shells.BASH, default=Shells.BASH)
         shells.add_argument("--fish", action="store_const", dest=shells_dest, const=Shells.FISH)
 
-        completion.add_argument(
-            "--args",
-            help="arguments to complete",
-            nargs=argparse.REMAINDER,
-            default=[]
-        )
+        completion.add_argument("--args", help="arguments to complete", nargs=argparse.REMAINDER, default=[])
 
         return completion, CompletionCommand
 
index 786c15c2c4473b9c348bbf68fae3039bd020ad20..4ba065ec56122703d4ace016c5799e6fe16ac40e 100644 (file)
@@ -3,15 +3,7 @@ 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,
-    get_subparser_by_name,
-    get_subparsers_words,
-    get_subparser_command,
-    register_command,
-)
+from knot_resolver.client.command import Command, CommandArgs, CompWords, 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