8000 fix(cli): preserve repeated --file flags by tayfuryldz · Pull Request #195 · habit-hooks/habit-hooks · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/habit_hooks/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Scope:
def resolve_scope(args: argparse.Namespace, config: Config, project_dir: Path) -> Scope:
placed = _placed(_selected(args, config, project_dir), project_dir)
files = _source_files(placed, config, project_dir)
notices = [] if files else empty_scope_notices(args.file, project_dir, config)
notices = [] if files else empty_scope_notices(args.file[-1] if args.file else None, project_dir, config)
if args.file is None:
notices = [*submodule_notices(placed, config, project_dir), *notices]
return Scope(files, notices)
Expand All @@ -36,7 +36,7 @@ def _selected(
args: argparse.Namespace, config: Config, project_dir: Path
) -> list[str]:
if args.file is not None:
return [args.file]
return args.file
if args.branch is not None:
base = args.branch or config.scope.branchBase
return _changed_since(
Expand Down
2 changes: 1 addition & 1 deletion src/habit_hooks/sensors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def build_parser(prog: str) -> argparse.ArgumentParser:
parser.add_argument("--no-snooze", action="store_true")
modes = parser.add_mutually_exclusive_group()
modes.add_argument("--all", action="store_true")
modes.add_argument("--file")
modes.add_argument("--file", action="append")
modes.add_argument("--branch", nargs="?", const="", metavar="base")
modes.add_argument("--last", type=_positive_int)
modes.add_argument("--since")
Expand Down
6 changes: 6 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ def fail(_: list[str]) -> int:

assert run_console("habit-sensors", fail, []) == 2
assert capsys.readouterr().err == "habit-sensors: not a git repository\n"


def test_repeated_file_flags_are_preserved() -> None:
parsed = sensors.parse_args(["--file", "a.md", "--file", "b.md"])

assert parsed.file == ["a.md", "b.md"]
12 changes: 12 additions & 0 deletions tests/test_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ def test_a_named_file_inside_files_is_scanned(tmp_path: Path) -> None:
assert scoped == ["src/a.py"]


def test_repeated_named_files_are_all_in_scope(tmp_path: Path) -> None:
source = _source_file(tmp_path)
second = source.with_name("b.py")
second.write_text("", encoding="utf-8")
scoped = _scoped_files(
["--file", "src/a.py", "--file", "src/b.py"],
tmp_path,
Config(files=["src/**"]),
)
assert scoped == ["src/a.py", "src/b.py"]


def test_an_absolute_named_file_is_placed_in_the_project(tmp_path: Path) -> None:
absolute = str(_source_file(tmp_path))
scoped = _scoped_files(["--file", absolute], tmp_path, Config(files=["src/**"]))
Expand Down
Loading
0