Skip to content

Commit 8c075ef

Browse files
committed
ci: fix ci
1 parent 464a9bc commit 8c075ef

File tree

1 file changed

+44
-23
lines changed
  • leetcode_py/cli/commands

1 file changed

+44
-23
lines changed

leetcode_py/cli/commands/gen.py

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ def _get_problem_difficulty(problem_name: str) -> str | None:
2727
return None
2828

2929

30-
def resolve_problems(
30+
def _validate_single_option(
3131
problem_nums: list[int],
3232
problem_slugs: list[str],
3333
problem_tag: str | None,
34-
difficulty: str | None,
3534
all_problems: bool,
36-
) -> list[str]:
35+
) -> None:
3736
options_count = sum(
3837
[
3938
len(problem_nums) > 0,
@@ -50,36 +49,58 @@ def resolve_problems(
5049
)
5150
raise typer.Exit(1)
5251

52+
53+
def _resolve_by_numbers(problem_nums: list[int]) -> list[str]:
5354
problems = []
55+
for num in problem_nums:
56+
problem_name = find_problem_by_number(num)
57+
if not problem_name:
58+
typer.echo(f"Error: Problem number {num} not found", err=True)
59+
raise typer.Exit(1)
60+
problems.append(problem_name)
61+
return problems
62+
63+
64+
def _resolve_by_tag(problem_tag: str) -> list[str]:
65+
problems = find_problems_by_tag(problem_tag)
66+
if not problems:
67+
typer.echo(f"Error: No problems found with tag '{problem_tag}'", err=True)
68+
raise typer.Exit(1)
69+
typer.echo(f"Found {len(problems)} problems with tag '{problem_tag}'")
70+
return problems
71+
72+
73+
def _filter_by_difficulty(problems: list[str], difficulty: str) -> list[str]:
74+
filtered_problems = []
75+
for problem_name in problems:
76+
problem_difficulty = _get_problem_difficulty(problem_name)
77+
if problem_difficulty and problem_difficulty.lower() == difficulty.lower():
78+
filtered_problems.append(problem_name)
79+
typer.echo(f"Filtered to {len(filtered_problems)} problems with difficulty '{difficulty}'")
80+
return filtered_problems
81+
82+
83+
def resolve_problems(
84+
problem_nums: list[int],
85+
problem_slugs: list[str],
86+
problem_tag: str | None,
87+
difficulty: str | None,
88+
all_problems: bool,
89+
) -> list[str]:
90+
_validate_single_option(problem_nums, problem_slugs, problem_tag, all_problems)
5491

5592
if problem_nums:
56-
for num in problem_nums:
57-
problem_name = find_problem_by_number(num)
58-
if not problem_name:
59-
typer.echo(f"Error: Problem number {num} not found", err=True)
60-
raise typer.Exit(1)
61-
problems.append(problem_name)
93+
problems = _resolve_by_numbers(problem_nums)
6294
elif problem_slugs:
6395
problems = problem_slugs
6496
elif problem_tag:
65-
problems = find_problems_by_tag(problem_tag)
66-
if not problems:
67-
typer.echo(f"Error: No problems found with tag '{problem_tag}'", err=True)
68-
raise typer.Exit(1)
69-
typer.echo(f"Found {len(problems)} problems with tag '{problem_tag}'")
70-
elif all_problems:
97+
problems = _resolve_by_tag(problem_tag)
98+
else: # all_problems
7199
problems = get_all_problems()
72100
typer.echo(f"Found {len(problems)} problems")
73101

74-
# Apply difficulty filter if specified
75102
if difficulty:
76-
filtered_problems = []
77-
for problem_name in problems:
78-
problem_difficulty = _get_problem_difficulty(problem_name)
79-
if problem_difficulty and problem_difficulty.lower() == difficulty.lower():
80-
filtered_problems.append(problem_name)
81-
problems = filtered_problems
82-
typer.echo(f"Filtered to {len(problems)} problems with difficulty '{difficulty}'")
103+
problems = _filter_by_difficulty(problems, difficulty)
83104

84105
return problems
85106

0 commit comments

Comments
 (0)