diff --git a/project/app.py b/project/app.py index e385b11..ed5f59d 100644 --- a/project/app.py +++ b/project/app.py @@ -23,12 +23,16 @@ def main(name: str = "World"): Args: name: the name to be greeted """ + name = name.strip() or "World" + if len(name) > 100: - raise UsageError("Invalid name: maximum length is 100 characters.") + raise UsageError(f"Name too long ({len(name)}/100 characters). Please keep it under 100.") if any(not c.isprintable() for c in name): raise UsageError("Invalid name: control characters are not allowed.") - secho(f"Hello {name}! 👋", fg="green", bold=True) + secho("Hello ", nl=False) + secho(name, fg="cyan", bold=True, nl=False) + secho("! 👋", fg="green", bold=True) if __name__ == "__main__": diff --git a/tests/test_app.py b/tests/test_app.py index 7c414cd..7b9842b 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -30,7 +30,7 @@ def test_name_too_long(): runner = CliRunner() result = runner.invoke(main, ["--name", "A" * 101]) assert result.exit_code != 0 - assert "maximum length is 100 characters" in result.output + assert "Name too long (101/100 characters)" in result.output def test_name_control_characters():