#!/usr/bin/env python
import sys
import click

from dotenv2k8s.main import create_k8s_manifest, create_pod_spec_as_envvar


@click.command()
@click.option(
    "--path",
    type=click.Path(exists=True),
    help="Path to the dotenv file.",
    required=True,
)
@click.option("--name", prompt="Secret name", help="The Secret name.", required=True)
@click.option(
    "--namespace",
    prompt="Kubernetes Namespace",
    help="The Kubernetes Namespace",
    default="default",
)
def main(path, name, namespace):
    metadata = {"name": name, "namespace": namespace}
    manifest = create_k8s_manifest(path, metadata)
    pode_spec = create_pod_spec_as_envvar(manifest, metadata)
    click.echo("---")
    click.echo(manifest)
    click.echo(f"Output file: secret-{metadata['name']}-{metadata['namespace']}.yaml")
    click.echo(
        f"kubectl apply -f secret-{metadata['name']}-{metadata['namespace']}.yaml"
    )
    click.echo("---")
    click.echo(
        "# POD spec for more information go to https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets-as-environment-variables"
    )
    click.echo(pode_spec)



if __name__ == '__main__':
    sys.exit(main())