From c928c9bd97287f0eda9583f4fe2931fb9d78118c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Varga?= Date: Mon, 16 Mar 2026 14:47:00 +0100 Subject: [PATCH] Add --shout to print the greeting in capitals Use str.upper() so that accented names keep their accents. --- README.md | 2 ++ src/hello_hut/cli.py | 5 ++++- src/hello_hut/greetings.py | 4 ++-- tests/test_greetings.py | 6 ++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 563463e26dd004cda10b13e5a64077b68bccb7f6..7e74e12da14a8720a603fec2e6e0e5f5a8ba29cb 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ $ hello-hut Hello, friend! $ hello-hut Ada Hello, Ada! +$ hello-hut Ada --shout +HELLO, ADA! ``` ## License diff --git a/src/hello_hut/cli.py b/src/hello_hut/cli.py index 9110eb394310a53122d8e131c3e593abd80647a3..b8cd9bd124af7a30a8fd31259100dd03c8f98ef2 100644 --- a/src/hello_hut/cli.py +++ b/src/hello_hut/cli.py @@ -13,6 +13,8 @@ def build_parser(): description="A friendly greeting tool for your terminal.", ) parser.add_argument("name", nargs="?", help="who to greet") + parser.add_argument("--shout", action="store_true", + help="print the greeting in capitals") parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}") return parser @@ -21,7 +23,8 @@ def build_parser(): def main(argv=None): args = build_parser().parse_args(argv) name = args.name or DEFAULT_NAME + shout = args.shout - message = greet(name) + message = greet(name, shout=shout) print(message) return 0 diff --git a/src/hello_hut/greetings.py b/src/hello_hut/greetings.py index 92cd435302e0c399d6aea19d6ea3e0c0e7789596..4e8891ed3e37cade88ad5871c2729e6cfe56182c 100644 --- a/src/hello_hut/greetings.py +++ b/src/hello_hut/greetings.py @@ -3,8 +3,8 @@ DEFAULT_NAME = "friend" -def greet(name=DEFAULT_NAME): +def greet(name=DEFAULT_NAME, shout=False): """Build a greeting such as "Hello, Ada!".""" salutation = "Hello" message = f"{salutation}, {name}!" - return message + return message.upper() if shout else message diff --git a/tests/test_greetings.py b/tests/test_greetings.py index 67cfbda2d04b773ff4a4a3d590911414d9e5a474..616e79a544a6726f2bb5301c6b8ca0009c7c6673 100644 --- a/tests/test_greetings.py +++ b/tests/test_greetings.py @@ -10,6 +10,12 @@ class GreetTest(unittest.TestCase): def test_custom_name(self): self.assertEqual(greet("Ada"), "Hello, Ada!") + def test_shout(self): + self.assertEqual(greet("Ada", shout=True), "HELLO, ADA!") + + def test_shout_keeps_accents(self): + self.assertEqual(greet("Zoë", shout=True), "HELLO, ZOË!") + if __name__ == "__main__": unittest.main()