implement logging verbosity option, change cli options
This commit is contained in:
parent
b26cfc2784
commit
941b993287
2 changed files with 69 additions and 48 deletions
115
src/zona/cli.py
115
src/zona/cli.py
|
@ -8,53 +8,6 @@ from zona.log import setup_logging
|
|||
|
||||
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()
|
||||
def init(
|
||||
|
@ -76,5 +29,73 @@ def init(
|
|||
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():
|
||||
app()
|
||||
|
|
|
@ -6,7 +6,7 @@ _LOGGER_NAME = "zona"
|
|||
|
||||
|
||||
def setup_logging(
|
||||
level: Literal["INFO", "DEBUG", "WARN", "ERROR"] = "INFO",
|
||||
level: str = "INFO",
|
||||
):
|
||||
logger = logging.getLogger(_LOGGER_NAME)
|
||||
logger.setLevel(level.upper())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue