Checkpoint

Checkpoint: The Harbor Launcher

The harbor needs a small command-line tool to light a lantern. It must behave like a professional tool:

  • settings come from the command line first, then an environment variable, then a default;
  • it logs what it does, with extra detail when asked;
  • it's typed and documented.
$ LANTERN_FUEL=7 launch Ember --verbose
INFO: lighting Ember
DEBUG: fuel=7

make_logger (from the logging lesson) is ready for you.

Assignment

  1. Finish build_parser(): a positional island, --fuel (an int, default None) and a --verbose flag.
  2. Finish main(argv=None, env=None, stream=None):
    • use os.environ when env is None;
    • the fuel is --fuel if given, otherwise LANTERN_FUEL from env as an int, otherwise 10;
    • make the logger with make_logger(stream, level), where level is "DEBUG" with --verbose and "INFO" without it;
    • log lighting <island> at INFO and fuel=<fuel> at DEBUG;
    • return "Lit <island> with <fuel> fuel".
  3. Give main a docstring and type hints, returning str.