Skip to content

Commit 2cf5881

Browse files
committed
cli: Add --only-old argument to all commands
By default, all commands show all annotations, branches, etc., including those that are recent. When exporting to a CSV format, it's useful to filter out the recent items and only display old ones.
1 parent 32aef2b commit 2cf5881

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

src/check_oldies/annotations.py

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Config:
2222
max_age: int = 180
2323

2424
output_format: output.OutputFormat = output.OutputFormat.TEXT
25+
only_old: bool = False
2526
colorize_errors: bool = True
2627

2728
annotations: typing.Sequence = ("todo", "fixme", ) # no-check-fixmes

src/check_oldies/branches.py

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Config:
4343

4444
output_format: output.OutputFormat = output.OutputFormat.TEXT
4545
colorize_errors: bool = True
46+
only_old: bool = False
4647

4748
calm_branches: typing.Sequence = ("gh-pages", "master", "main", "prod", "maint(enance)?/.*")
4849
ignore_branches_without_pull_request: bool = False

src/check_oldies/check_branches.py

+8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ def get_parser():
4343
f"Defaults to {check_oldies.branches.Config.max_age}."
4444
),
4545
)
46+
parser.add_argument(
47+
"--only-old",
48+
action="store_true",
49+
default=False,
50+
help="Show only old branches. By default, the command shows all branches."
51+
)
4652
parser.add_argument(
4753
"--no-color",
4854
action="store_false",
@@ -62,6 +68,8 @@ def main():
6268
sys.exit(f'Invalid path: "{config.path}" is not a Git repository.')
6369

6470
branches = check_oldies.branches.get_branches(config)
71+
if config.only_old:
72+
branches = [branch for branch in branches if branch.is_old]
6573
branches.sort(key=lambda branch: (branch.author, -branch.age, branch.name))
6674
has_old_branches = any(branch for branch in branches if branch.is_old)
6775

src/check_oldies/check_fixmes.py

+8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ def get_parser():
4343
f"Defaults to {check_oldies.annotations.Config.max_age}."
4444
),
4545
)
46+
parser.add_argument(
47+
"--only-old",
48+
action="store_true",
49+
default=False,
50+
help="Show only old annotations. By default, the command shows all annotations."
51+
)
4652
parser.add_argument(
4753
"--no-color",
4854
action="store_false",
@@ -62,6 +68,8 @@ def main():
6268
sys.exit(f'Invalid path: "{config.path}" is not a Git repository.')
6369

6470
annotations = check_oldies.annotations.get_annotations(config)
71+
if config.only_old:
72+
annotations = [a for a in annotations if a.is_old]
6573
annotations.sort(key=lambda f: (f.assignee, -f.age, f.filename, f.line_no))
6674
has_old_annotations = any(ann for ann in annotations if ann.is_old)
6775

0 commit comments

Comments
 (0)