|
| 1 | +""" |
| 2 | +CLI commands for managing the environment file. |
| 3 | +""" |
| 4 | + |
| 5 | +import click |
| 6 | +from jinja2 import Environment, PackageLoader |
| 7 | + |
| 8 | +from cli.eest.quotes import get_quote |
| 9 | +from config.env import ENV_PATH, Config |
| 10 | + |
| 11 | + |
| 12 | +@click.command(short_help="Generate the default environment file (env.yaml).", name="env") |
| 13 | +def create_default_env(): |
| 14 | + """ |
| 15 | + A CLI command to generate the default environment file (env.yaml). |
| 16 | +
|
| 17 | + If an `env.yaml` already exists, this command will NOT override it. |
| 18 | + In that case, it is recommended to manually make changes. |
| 19 | +
|
| 20 | + _Easter egg: Shows a random quote after creating the environment file._ |
| 21 | +
|
| 22 | + Example: |
| 23 | +
|
| 24 | + uv run eest make env |
| 25 | +
|
| 26 | + Output: |
| 27 | +
|
| 28 | + 🎉 Success! Environment file created at: <path>/env.yaml |
| 29 | +
|
| 30 | + 🚀 Well begun is half done. - Aristotle |
| 31 | + """ |
| 32 | + # Check if the env file already exists |
| 33 | + if ENV_PATH.exists(): |
| 34 | + click.echo( |
| 35 | + click.style( |
| 36 | + f"🚧 The env file '{ENV_PATH}' already exists. " |
| 37 | + "Please update it manually if needed.", |
| 38 | + fg="red", |
| 39 | + ) |
| 40 | + ) |
| 41 | + exit(1) |
| 42 | + |
| 43 | + template_environment = Environment( |
| 44 | + loader=PackageLoader("config"), trim_blocks=True, lstrip_blocks=True |
| 45 | + ) |
| 46 | + template = template_environment.get_template("env.yaml.j2") |
| 47 | + |
| 48 | + env_yaml = template.render(config=Config()) |
| 49 | + |
| 50 | + with ENV_PATH.open("w") as file: |
| 51 | + file.write(env_yaml) |
| 52 | + click.echo(click.style(f"🎉 Success! Environment file created at: {ENV_PATH}", fg="green")) |
| 53 | + click.echo(get_quote()) |
0 commit comments