~reviewer/hello-hut

ddfb81baa28381acf464f1a5be37c0be23854fcb — Dana Whitfield 7 months ago ea92a9b
Add greeting module and command-line entry point

hello-hut greets whoever is passed with --name, or "friend" by
default.
M README.md => README.md +6 -1
@@ 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


A src/hello_hut/__init__.py => src/hello_hut/__init__.py +3 -0
@@ 0,0 1,3 @@
"""hello-hut: a friendly greeting tool for your terminal."""

__version__ = "0.1.0.dev0"

A src/hello_hut/__main__.py => src/hello_hut/__main__.py +3 -0
@@ 0,0 1,3 @@
from .cli import main

raise SystemExit(main())

A src/hello_hut/cli.py => src/hello_hut/cli.py +28 -0
@@ 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

A src/hello_hut/greetings.py => src/hello_hut/greetings.py +10 -0
@@ 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