From ddfb81baa28381acf464f1a5be37c0be23854fcb Mon Sep 17 00:00:00 2001 From: Dana Whitfield Date: Mon, 2 Mar 2026 11:40:00 +0100 Subject: [PATCH] Add greeting module and command-line entry point hello-hut greets whoever is passed with --name, or "friend" by default. --- README.md | 7 ++++++- src/hello_hut/__init__.py | 3 +++ src/hello_hut/__main__.py | 3 +++ src/hello_hut/cli.py | 28 ++++++++++++++++++++++++++++ src/hello_hut/greetings.py | 10 ++++++++++ 5 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/hello_hut/__init__.py create mode 100644 src/hello_hut/__main__.py create mode 100644 src/hello_hut/cli.py create mode 100644 src/hello_hut/greetings.py diff --git a/README.md b/README.md index cd9ae54eb0a14aa42b2065fa59b7bbdd264fdec8..b65dd952f84e8d5364dc014b80a5059f8173a51e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,12 @@ **hello-hut** is a small, friendly greeting tool for your terminal. It says hello — and that is all it does. -This project is just getting started. +## Usage + +```console +$ hello-hut --name Ada +Hello, Ada! +``` ## License diff --git a/src/hello_hut/__init__.py b/src/hello_hut/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..53e9adabe45f78a21083dbc2e3ce7def7ca0325c --- /dev/null +++ b/src/hello_hut/__init__.py @@ -0,0 +1,3 @@ +"""hello-hut: a friendly greeting tool for your terminal.""" + +__version__ = "0.1.0.dev0" diff --git a/src/hello_hut/__main__.py b/src/hello_hut/__main__.py new file mode 100644 index 0000000000000000000000000000000000000000..eb53e2f31b2f703ad32ef64b8a41faa3e7d18e08 --- /dev/null +++ b/src/hello_hut/__main__.py @@ -0,0 +1,3 @@ +from .cli import main + +raise SystemExit(main()) diff --git a/src/hello_hut/cli.py b/src/hello_hut/cli.py new file mode 100644 index 0000000000000000000000000000000000000000..69398d0dd94f4cacf1a6985ecd337688d65a30a9 --- /dev/null +++ b/src/hello_hut/cli.py @@ -0,0 +1,28 @@ +"""Command-line interface for hello-hut.""" + +import argparse +import sys + +from . import __version__ +from .greetings import DEFAULT_NAME, greet + + +def build_parser(): + parser = argparse.ArgumentParser( + prog="hello-hut", + description="A friendly greeting tool for your terminal.", + ) + parser.add_argument("--name", default=DEFAULT_NAME, + help="who to greet (default: %(default)s)") + parser.add_argument("--version", action="version", + version=f"%(prog)s {__version__}") + return parser + + +def main(argv=None): + args = build_parser().parse_args(argv) + name = args.name + + message = greet(name) + print(message) + return 0 diff --git a/src/hello_hut/greetings.py b/src/hello_hut/greetings.py new file mode 100644 index 0000000000000000000000000000000000000000..92cd435302e0c399d6aea19d6ea3e0c0e7789596 --- /dev/null +++ b/src/hello_hut/greetings.py @@ -0,0 +1,10 @@ +"""Greeting construction: pure functions with no I/O, easy to test.""" + +DEFAULT_NAME = "friend" + + +def greet(name=DEFAULT_NAME): + """Build a greeting such as "Hello, Ada!".""" + salutation = "Hello" + message = f"{salutation}, {name}!" + return message