Skip to content

Commit abf8beb

Browse files
committed
cli/__init__(refactor[create_parser]): Simplify parser return handling
why: The create_parser function was over-engineered with complex overloads and dictionary returns when a simple tuple would suffice. what: - Remove get_all_subparsers parameter and its complex overload - Return simple tuple (parser, subparsers_tuple) instead of dictionary - Use direct tuple unpacking in cli() function - Remove unnecessary dictionary lookups for subparsers - Maintain backward compatibility with existing return pattern This follows the existing vcspull pattern of keeping things simple and direct rather than adding unnecessary abstraction layers.
1 parent e2ad1da commit abf8beb

File tree

1 file changed

+5
-36
lines changed

1 file changed

+5
-36
lines changed

src/vcspull/cli/__init__.py

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,9 @@ def create_parser(
4444
def create_parser(return_subparsers: t.Literal[False]) -> argparse.ArgumentParser: ...
4545

4646

47-
@overload
48-
def create_parser(
49-
return_subparsers: t.Literal[True],
50-
get_all_subparsers: t.Literal[True],
51-
) -> tuple[
52-
argparse.ArgumentParser,
53-
argparse._SubParsersAction[argparse.ArgumentParser],
54-
dict[str, argparse.ArgumentParser],
55-
]: ...
56-
57-
5847
def create_parser(
5948
return_subparsers: bool = False,
60-
get_all_subparsers: bool = False,
61-
) -> (
62-
argparse.ArgumentParser
63-
| tuple[argparse.ArgumentParser, t.Any]
64-
| tuple[
65-
argparse.ArgumentParser,
66-
argparse._SubParsersAction[argparse.ArgumentParser],
67-
dict[str, argparse.ArgumentParser],
68-
]
69-
):
49+
) -> argparse.ArgumentParser | tuple[argparse.ArgumentParser, t.Any]:
7050
"""Create CLI argument parser for vcspull."""
7151
parser = argparse.ArgumentParser(
7252
prog="vcspull",
@@ -113,24 +93,16 @@ def create_parser(
11393
)
11494
create_add_from_fs_subparser(add_from_fs_parser)
11595

116-
if get_all_subparsers and return_subparsers:
117-
all_parsers = {
118-
"sync": sync_parser,
119-
"add": add_parser,
120-
"add_from_fs": add_from_fs_parser,
121-
}
122-
return parser, subparsers, all_parsers
12396
if return_subparsers:
124-
return parser, sync_parser
97+
# Return all parsers needed by cli() function
98+
return parser, (sync_parser, add_parser, add_from_fs_parser)
12599
return parser
126100

127101

128102
def cli(_args: list[str] | None = None) -> None:
129103
"""CLI entry point for vcspull."""
130-
parser, _subparsers_action, all_parsers = create_parser(
131-
return_subparsers=True,
132-
get_all_subparsers=True,
133-
)
104+
parser, subparsers = create_parser(return_subparsers=True)
105+
sync_parser, add_parser, add_from_fs_parser = subparsers
134106
args = parser.parse_args(_args)
135107

136108
setup_logger(log=log, level=args.log_level.upper())
@@ -139,7 +111,6 @@ def cli(_args: list[str] | None = None) -> None:
139111
parser.print_help()
140112
return
141113
if args.subparser_name == "sync":
142-
sync_parser = all_parsers["sync"]
143114
sync(
144115
repo_patterns=args.repo_patterns if hasattr(args, "repo_patterns") else [],
145116
config=(
@@ -153,7 +124,6 @@ def cli(_args: list[str] | None = None) -> None:
153124
parser=sync_parser,
154125
)
155126
elif args.subparser_name == "add":
156-
all_parsers["add"]
157127
add_repo_kwargs = {
158128
"name": args.name,
159129
"url": args.url,
@@ -163,7 +133,6 @@ def cli(_args: list[str] | None = None) -> None:
163133
}
164134
add_repo(**add_repo_kwargs)
165135
elif args.subparser_name == "add-from-fs":
166-
all_parsers["add_from_fs"]
167136
add_from_fs_kwargs = {
168137
"scan_dir_str": args.scan_dir,
169138
"config_file_path_str": args.config if hasattr(args, "config") else None,

0 commit comments

Comments
 (0)