~reviewer/hello-hut

c928c9bd97287f0eda9583f4fe2931fb9d78118c — Tomás Varga 7 months ago 8f1a289
Add --shout to print the greeting in capitals

Use str.upper() so that accented names keep their accents.
4 files changed, 14 insertions(+), 3 deletions(-)

M README.md
M src/hello_hut/cli.py
M src/hello_hut/greetings.py
M tests/test_greetings.py
M README.md => README.md +2 -0
@@ 10,6 10,8 @@ $ hello-hut
Hello, friend!
$ hello-hut Ada
Hello, Ada!
$ hello-hut Ada --shout
HELLO, ADA!
```

## License

M src/hello_hut/cli.py => src/hello_hut/cli.py +4 -1
@@ 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

M src/hello_hut/greetings.py => src/hello_hut/greetings.py +2 -2
@@ 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

M tests/test_greetings.py => tests/test_greetings.py +6 -0
@@ 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()