|
64 | 64 | PURE_PYTHON_MSGPACK_WARNING = "Using a pure-python msgpack! This will result in lower performance." |
65 | 65 |
|
66 | 66 |
|
67 | | -# Command dispatch table: maps subcommand names to method names on the Archiver class. |
68 | | -# For nested subcommands (key, debug, benchmark), the value is a dict mapping |
69 | | -# the nested subcommand name to the method name. |
70 | | -COMMAND_DISPATCH = { |
71 | | - "analyze": "do_analyze", |
72 | | - "benchmark": {"crud": "do_benchmark_crud", "cpu": "do_benchmark_cpu"}, |
73 | | - "break-lock": "do_break_lock", |
74 | | - "check": "do_check", |
75 | | - "compact": "do_compact", |
76 | | - "completion": "do_completion", |
77 | | - "create": "do_create", |
78 | | - "debug": { |
79 | | - "info": "do_debug_info", |
80 | | - "dump-archive-items": "do_debug_dump_archive_items", |
81 | | - "dump-archive": "do_debug_dump_archive", |
82 | | - "dump-manifest": "do_debug_dump_manifest", |
83 | | - "dump-repo-objs": "do_debug_dump_repo_objs", |
84 | | - "search-repo-objs": "do_debug_search_repo_objs", |
85 | | - "id-hash": "do_debug_id_hash", |
86 | | - "parse-obj": "do_debug_parse_obj", |
87 | | - "format-obj": "do_debug_format_obj", |
88 | | - "get-obj": "do_debug_get_obj", |
89 | | - "put-obj": "do_debug_put_obj", |
90 | | - "delete-obj": "do_debug_delete_obj", |
91 | | - "convert-profile": "do_debug_convert_profile", |
92 | | - }, |
93 | | - "delete": "do_delete", |
94 | | - "diff": "do_diff", |
95 | | - "export-tar": "do_export_tar", |
96 | | - "extract": "do_extract", |
97 | | - "help": "do_help", |
98 | | - "import-tar": "do_import_tar", |
99 | | - "info": "do_info", |
100 | | - "key": { |
101 | | - "change-passphrase": "do_change_passphrase", |
102 | | - "change-location": "do_change_location", |
103 | | - "export": "do_key_export", |
104 | | - "import": "do_key_import", |
105 | | - }, |
106 | | - "list": "do_list", |
107 | | - "mount": "do_mount", |
108 | | - "prune": "do_prune", |
109 | | - "repo-compress": "do_repo_compress", |
110 | | - "repo-create": "do_repo_create", |
111 | | - "repo-delete": "do_repo_delete", |
112 | | - "repo-info": "do_repo_info", |
113 | | - "repo-list": "do_repo_list", |
114 | | - "repo-space": "do_repo_space", |
115 | | - "recreate": "do_recreate", |
116 | | - "rename": "do_rename", |
117 | | - "serve": "do_serve", |
118 | | - "tag": "do_tag", |
119 | | - "transfer": "do_transfer", |
120 | | - "umount": "do_umount", |
121 | | - "undelete": "do_undelete", |
122 | | - "version": "do_version", |
123 | | - "with-lock": "do_with_lock", |
124 | | -} |
125 | | - |
126 | | - |
127 | 67 | from .analyze_cmd import AnalyzeMixIn |
128 | 68 | from .benchmark_cmd import BenchmarkMixIn |
129 | 69 | from .check_cmd import CheckMixIn |
@@ -462,24 +402,23 @@ def get_func(self, args): |
462 | 402 | if subcmd is None: |
463 | 403 | return functools.partial(self.do_maincommand_help, self.parser) |
464 | 404 |
|
465 | | - dispatch = COMMAND_DISPATCH.get(subcmd) |
466 | | - if dispatch is None: |
467 | | - return functools.partial(self.do_maincommand_help, self.parser) |
| 405 | + subcmd_ns = getattr(args, subcmd, None) |
| 406 | + nested_subcmd = getattr(subcmd_ns, "subcommand", None) if subcmd_ns else None |
468 | 407 |
|
469 | | - if isinstance(dispatch, dict): |
470 | | - # Nested subcommand (key, debug, benchmark) |
471 | | - subcmd_ns = getattr(args, subcmd, None) |
472 | | - nested_subcmd = getattr(subcmd_ns, "subcommand", None) if subcmd_ns else None |
473 | | - if nested_subcmd is None: |
474 | | - # No nested subcommand given, show subcommand help |
475 | | - # We need the parser for the mid-level command |
476 | | - return functools.partial(self.do_subcommand_help, self.parser) |
477 | | - method_name = dispatch.get(nested_subcmd) |
478 | | - if method_name is None: |
479 | | - return functools.partial(self.do_subcommand_help, self.parser) |
480 | | - func = getattr(self, method_name) |
| 408 | + if nested_subcmd is None: |
| 409 | + method_name = f"do_{subcmd}".replace("-", "_") |
481 | 410 | else: |
482 | | - func = getattr(self, dispatch) |
| 411 | + method_name = f"do_{subcmd}_{nested_subcmd}".replace("-", "_") |
| 412 | + |
| 413 | + func = getattr(self, method_name, None) |
| 414 | + |
| 415 | + if func is None: |
| 416 | + # Fallback for container commands or unknown commands |
| 417 | + if nested_subcmd is None and subcmd_ns is not None: |
| 418 | + # Might be a container command without a subcommand selected (e.g. just "borg key") |
| 419 | + subparser = getattr(self, "_commands", {}).get(subcmd) |
| 420 | + return functools.partial(self.do_subcommand_help, subparser or self.parser) |
| 421 | + return functools.partial(self.do_maincommand_help, self.parser) |
483 | 422 |
|
484 | 423 | # Special handling for "help" command which needs extra args |
485 | 424 | if subcmd == "help": |
|
0 commit comments