diff --git a/docs/docs/user/references/cli-commands.md b/docs/docs/user/references/cli-commands.md index ed321367b..6a4c2a419 100644 --- a/docs/docs/user/references/cli-commands.md +++ b/docs/docs/user/references/cli-commands.md @@ -19,6 +19,7 @@ $ kpops [OPTIONS] COMMAND [ARGS]... * `deploy`: Deploy pipeline steps * `destroy`: Destroy pipeline steps * `generate`: Enriches pipelines steps with defaults. +* `init`: Create a new a KPOps project. * `reset`: Reset pipeline steps * `schema`: Generate json schema. @@ -134,6 +135,25 @@ $ kpops generate [OPTIONS] PIPELINE_PATH [COMPONENTS_MODULE] * `--environment TEXT`: The environment you want to generate and deploy the pipeline to. Suffix your environment files with this value (e.g. defaults_development.yaml for environment=development). [env var: KPOPS_ENVIRONMENT] * `--help`: Show this message and exit. +## `kpops init` + +Create a new a KPOps project. + +**Usage**: + +```console +$ kpops init [OPTIONS] PATH +``` + +**Arguments**: + +* `PATH`: Path for a new KPOps project. [required] + +**Options**: + +* `--name TEXT`: Name of the new KPOps project. A new directory with the provided name will be created. Leave empty to use the existing dir provided via `--path`. +* `--help`: Show this message and exit. + ## `kpops reset` Reset pipeline steps diff --git a/kpops/cli/main.py b/kpops/cli/main.py index 264cd170d..d03eb1d4f 100644 --- a/kpops/cli/main.py +++ b/kpops/cli/main.py @@ -8,7 +8,6 @@ import dtyper import typer -from hooks.gen_docs.gen_docs_env_vars import collect_fields from kpops import __version__ from kpops.cli.custom_formatter import CustomFormatter from kpops.cli.registry import Registry @@ -259,20 +258,15 @@ def init( path: Path = PROJECT_PATH, name: Optional[str] = PROJECT_NAME, ): - ... - # if name: - # path = path / name - # elif next(path.iterdir(), False): - # log.warning("Please provide a path to an empty directory.") - # return - # config_fields = collect_fields(PipelineConfig) - # path.mkdir(exist_ok=True) - # pipeline_name = "pipeline" - # defaults_name = "defaults" - # config_name = "config" - # for file_name in [pipeline_name, defaults_name, config_name]: - # file_name = file_name + ".yaml" - # Path(path / file_name).touch(exist_ok=False) + if name: + path = path / name + elif next(path.iterdir(), False): + log.warning("Please provide a path to an empty directory.") + return + path.mkdir(exist_ok=True) + pipeline_name = "pipeline" + defaults_name = "defaults" + config_name = "config" @app.command( # pyright: ignore[reportGeneralTypeIssues] https://github.com/rec/dtyper/issues/8 diff --git a/kpops/utils/cli_commands.py b/kpops/utils/cli_commands.py index d1be55bcf..73ece2688 100644 --- a/kpops/utils/cli_commands.py +++ b/kpops/utils/cli_commands.py @@ -1,26 +1,28 @@ - import logging from pathlib import Path -from hooks.gen_docs.gen_docs_env_vars import collect_fields -from kpops.cli.pipeline_config import PipelineConfig +from hooks.gen_docs.gen_docs_env_vars import collect_fields +from kpops.config import KpopsConfig log = logging.getLogger("cli_commands_utils") - + + def touch_yaml_file(file_name, dir_path) -> Path: file_path = Path(dir_path / (file_name + ".yaml")) file_path.touch(exist_ok=False) return file_path + def create_config(file_name: str, dir_path: Path) -> None: file_path = touch_yaml_file(file_name, dir_path) - config_fields = collect_fields(PipelineConfig) + config_fields = collect_fields(KpopsConfig) with file_path.open(mode="w"): - + ... def create_defaults(file_name: str, dir_path: Path) -> None: file_path = touch_yaml_file(file_name, dir_path) + def create_pipeline(file_name: str, dir_path: Path) -> None: file_path = touch_yaml_file(file_name, dir_path)