Skip to content

Commit

Permalink
Merge pull request #21 from moduon/init-no-cwd
Browse files Browse the repository at this point in the history
feat(init): accept dir argument, not always cwd
  • Loading branch information
sbidoul authored Jul 18, 2024
2 parents 23587c6 + 9dc4a55 commit 2c80cb0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/21.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
whool init now accepts a directory argument
11 changes: 9 additions & 2 deletions src/whool/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def main(argv: Optional[List[str]] = None) -> int:
action="store_true",
help="Exit with non-zero status if any changes were made.",
)
init_ap.add_argument(
"dir",
type=Path,
nargs="?",
default=Path.cwd(),
help="Addon(s) directory to initialize (default: current directory).",
)

args = ap.parse_args(argv)
if args.verbose >= 2:
Expand All @@ -51,10 +58,10 @@ def main(argv: Optional[List[str]] = None) -> int:
logging.basicConfig(level=log_level)

if args.subcmd == "init":
modified_files = init(Path.cwd())
modified_files = init(args.dir)
if args.exit_non_zero_on_changes and modified_files:
modified_str = ", ".join(
str(p.relative_to(Path.cwd())) for p in modified_files
str(p.relative_to(args.dir)) for p in modified_files
)
sys.stderr.write(
f"pyproject.toml was generated or modified in {modified_str}\n"
Expand Down
7 changes: 7 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,10 @@ def test_init_cli_nonzero_exit(
assert pyproject_toml_path.exists()
captured = capsys.readouterr()
assert captured.err == "pyproject.toml was generated or modified in .\n"


def test_init_cli_no_cwd(addon1: Path) -> None:
pyproject_toml_path = addon1 / "pyproject.toml"
assert not pyproject_toml_path.exists()
assert main(["init", "--exit-non-zero-on-changes", str(addon1)]) == 1
assert pyproject_toml_path.exists()

0 comments on commit 2c80cb0

Please sign in to comment.