feat: add cli option for length

This commit is contained in:
Ruidy 2021-07-05 19:20:57 +02:00
parent debe9c4565
commit fc6779af14
4 changed files with 24 additions and 7 deletions

View file

@ -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

View file

@ -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

View file

@ -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__":

View file

@ -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