diff --git a/cookie_composer/cli.py b/cookie_composer/cli.py index 2a1f24d..4d98bcf 100644 --- a/cookie_composer/cli.py +++ b/cookie_composer/cli.py @@ -1,14 +1,19 @@ """Command line setup.""" from typing import Optional +import logging from pathlib import Path +import click_log import rich_click as click from cookie_composer.commands.add import add_cmd from cookie_composer.commands.create import create_cmd from cookie_composer.exceptions import GitError +logger = logging.getLogger(__name__) +click_log.basic_config(logger) + @click.group() def cli(): @@ -17,6 +22,7 @@ def cli(): @cli.command() +@click_log.simple_verbosity_option(logger) @click.argument("path_or_url", type=str, required=True) @click.argument( "output_dir", @@ -25,17 +31,12 @@ def cli(): type=click.Path(exists=True, dir_okay=True, file_okay=False, resolve_path=True), ) def create(path_or_url: str, output_dir: Optional[Path]): - """ - Create a project from a template or configuration. - - Args: - path_or_url: The path or URL to the template or composition file - output_dir: Where to write the output - """ + """Create a project from a template or configuration.""" create_cmd(path_or_url, output_dir) @cli.command() +@click_log.simple_verbosity_option(logger) @click.option("--no-input", is_flag=True) @click.argument("path_or_url", type=str, required=True) @click.argument( diff --git a/cookie_composer/commands/add.py b/cookie_composer/commands/add.py index 74e5a91..660b55d 100644 --- a/cookie_composer/commands/add.py +++ b/cookie_composer/commands/add.py @@ -1,6 +1,7 @@ """The implementation of the add command.""" from typing import Optional +import logging from pathlib import Path from cookie_composer.composition import ( @@ -21,6 +22,8 @@ from cookie_composer.layers import render_layers from cookie_composer.utils import get_context_for_layer, get_template_name +logger = logging.getLogger(__name__) + def add_cmd( path_or_url: str, @@ -40,7 +43,7 @@ def add_cmd( GitError: If the destination_dir is not a git repository ValueError: If there is not a .composition.yaml file in the destination directory """ - destination_dir = destination_dir or Path(".") + destination_dir = Path(destination_dir).resolve() or Path().cwd().resolve() output_dir = destination_dir.parent # Read the project composition file @@ -53,9 +56,11 @@ def add_cmd( # Read the additional composition if is_composition_file(path_or_url): addl_composition = read_composition(path_or_url) + logger.info(f"Adding composition {path_or_url} to {output_dir}.") else: tmpl = LayerConfig(template=path_or_url) addl_composition = Composition(layers=[tmpl]) + logger.info(f"Adding template {path_or_url} to {output_dir}.") # Get the merged context for all layers initial_context = get_context_for_layer(proj_composition) diff --git a/cookie_composer/commands/create.py b/cookie_composer/commands/create.py index bfca969..e0788f4 100644 --- a/cookie_composer/commands/create.py +++ b/cookie_composer/commands/create.py @@ -2,6 +2,7 @@ from typing import Optional +import logging from pathlib import Path from cookie_composer.composition import ( @@ -14,6 +15,8 @@ ) from cookie_composer.layers import render_layers +logger = logging.getLogger(__name__) + def create_cmd( path_or_url: str, @@ -31,12 +34,14 @@ def create_cmd( Returns: The path to the generated project. """ - output_dir = output_dir or Path(".") + output_dir = Path(output_dir).resolve() or Path().cwd().resolve() if is_composition_file(path_or_url): composition = read_composition(path_or_url) + logger.info(f"Rendering composition {path_or_url} to {output_dir}.") else: tmpl = LayerConfig(template=path_or_url) composition = Composition(layers=[tmpl], destination=output_dir) + logger.info(f"Rendering template {path_or_url} to {output_dir}.") rendered_layers = render_layers(composition.layers, output_dir, no_input=no_input) rendered_composition = RenderedComposition( layers=rendered_layers, diff --git a/cookie_composer/composition.py b/cookie_composer/composition.py index 3f80d9e..d2214e1 100644 --- a/cookie_composer/composition.py +++ b/cookie_composer/composition.py @@ -249,6 +249,7 @@ def write_rendered_composition(composition: RenderedComposition): layers.append(rendered_layer.layer) composition_file = composition.render_dir / composition.rendered_name / ".composition.yaml" + logger.debug(f"Writing rendered composition to {composition_file}") write_composition(layers, composition_file) diff --git a/requirements/dev.txt b/requirements/dev.txt index dea783a..8523cbe 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -68,11 +68,14 @@ click==8.1.3 # -r docs.txt # -r test.txt # black + # click-log # pip-tools # rich-click # sphinx-click # typer # vendoring +click-log==0.4.0 + # via -r test.txt commonmark==0.9.1 # via # -r test.txt diff --git a/requirements/prod.in b/requirements/prod.in index 39dc465..bcbbb82 100644 --- a/requirements/prod.in +++ b/requirements/prod.in @@ -1,6 +1,7 @@ -r cookiecutter.txt aiohttp +click-log fsspec gitpython pydantic diff --git a/requirements/prod.txt b/requirements/prod.txt index e9525a6..c295864 100644 --- a/requirements/prod.txt +++ b/requirements/prod.txt @@ -34,7 +34,10 @@ charset-normalizer==2.0.12 click==8.1.3 # via # -r cookiecutter.txt + # click-log # rich-click +click-log==0.4.0 + # via -r prod.in commonmark==0.9.1 # via rich frozenlist==1.3.0 diff --git a/requirements/test.txt b/requirements/test.txt index d382b31..53793b5 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -46,7 +46,10 @@ click==8.1.3 # via # -r prod.txt # black + # click-log # rich-click +click-log==0.4.0 + # via -r prod.txt commonmark==0.9.1 # via # -r prod.txt