implement logging verbosity option, change cli options

This commit is contained in:
Daniel Fichtinger 2025-07-03 12:42:02 -04:00
parent b26cfc2784
commit 941b993287
2 changed files with 69 additions and 48 deletions

View file

@ -8,53 +8,6 @@ from zona.log import setup_logging
app = typer.Typer() app = typer.Typer()
setup_logging("DEBUG")
@app.command()
def build(
root: Annotated[
Path | None,
typer.Argument(
help="Directory containing config.yml",
),
] = None,
output: Annotated[
Path | None,
typer.Argument(help="Location to write built website"),
] = None,
):
"""
Build the website.
Optionally specify the ROOT and OUTPUT directories.
"""
builder = ZonaBuilder(root, output)
builder.build()
@app.command()
def serve(
root: Annotated[
Path | None,
typer.Argument(
help="Directory containing config.yml",
),
] = None,
output: Annotated[
Path | None,
typer.Argument(help="Location to write built website"),
] = None,
):
"""
Build the website and start a live preview server.
The website is rebuilt when the source is modified.
Optionally specify the ROOT and OUTPUT directories.
"""
server.serve(root, output)
@app.command() @app.command()
def init( def init(
@ -76,5 +29,73 @@ def init(
initialize_site(root) initialize_site(root)
@app.command()
def build(
root: Annotated[
Path | None,
typer.Argument(
help="Directory containing config.yml",
),
] = None,
output: Annotated[
Path | None,
typer.Option(
"--output", "-o", help="Location to write built website"
),
] = None,
):
"""
Build the website.
Optionally specify the ROOT and OUTPUT directories.
"""
builder = ZonaBuilder(root, output)
builder.build()
@app.command()
def serve(
root: Annotated[
Path | None,
typer.Argument(
help="Directory containing config.yml",
),
] = None,
output: Annotated[
Path | None,
typer.Option(
"--output", "-o", help="Location to write built website"
),
] = None,
):
"""
Build the website and start a live preview server.
The website is rebuilt when the source is modified.
Optionally specify the ROOT and OUTPUT directories.
"""
server.serve(root, output)
@app.callback()
def main_entry(
verbosity: Annotated[
str,
typer.Option(
"--verbosity",
"-v",
help="Logging verbosity. One of INFO, DEBUG, WARN, ERROR.",
),
] = "info",
) -> None:
"""
Opinionated static site generator.
Supply --help after any subcommand for more details.
"""
setup_logging(verbosity)
def main(): def main():
app() app()

View file

@ -6,7 +6,7 @@ _LOGGER_NAME = "zona"
def setup_logging( def setup_logging(
level: Literal["INFO", "DEBUG", "WARN", "ERROR"] = "INFO", level: str = "INFO",
): ):
logger = logging.getLogger(_LOGGER_NAME) logger = logging.getLogger(_LOGGER_NAME)
logger.setLevel(level.upper()) logger.setLevel(level.upper())