diff --git a/Makefile b/Makefile index a522fcd..bc273ee 100644 --- a/Makefile +++ b/Makefile @@ -12,5 +12,8 @@ test: .PHONY: cli cli: - pipenv run python app/main.py + pipenv run python -m app.main +.PHONY: help +help: + pipenv run python -m app.main --help diff --git a/README.md b/README.md index fef1018..5125298 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## Stories - [x] As a user I want to generate a random secure password to protect my personal accounts - - [ ] Minimal length + - [x] Minimal length - [ ] Include symbols - [ ] Include numbers - [ ] Include lowercase characters diff --git a/app/main.py b/app/main.py index 74cc6cc..7d5627d 100644 --- a/app/main.py +++ b/app/main.py @@ -6,8 +6,10 @@ app = typer.Typer() @app.command() -def main() -> None: - typer.echo(generate_password(0)) +def main( + length: int = typer.Option(8, help="Length of the generated password."), +) -> None: + typer.echo(generate_password(0, length)) if __name__ == "__main__": diff --git a/app/main_test.py b/app/main_test.py index 2ca6e54..1feb3bf 100644 --- a/app/main_test.py +++ b/app/main_test.py @@ -1,10 +1,22 @@ -from typer.testing import CliRunner +from typer.testing import CliRunner, Result + from .main import app runner = CliRunner() def test_cli_print_password() -> None: - result = runner.invoke(app) - assert result.exit_code == 0 + result = _run_cli() assert "2yW4AcqG" in result.stdout + + +def test_cli_can_set_password_length() -> None: + args = ["--length", 10] + result = _run_cli(*args) + assert "2yW4AcqGFz" in result.stdout + + +def _run_cli(*args) -> Result: + result = runner.invoke(app, args) + assert result.exit_code == 0 + return result