From f1a741b5e0d577cfa7c5657944dd807855f202d8 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sat, 31 Jan 2026 01:37:02 +0000 Subject: [PATCH] Add env_pro command modules --- app/env_pro/commands/export_cmd.py | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 app/env_pro/commands/export_cmd.py diff --git a/app/env_pro/commands/export_cmd.py b/app/env_pro/commands/export_cmd.py new file mode 100644 index 0000000..c86fe29 --- /dev/null +++ b/app/env_pro/commands/export_cmd.py @@ -0,0 +1,63 @@ +"""Export commands for env-pro.""" + +import click +from pathlib import Path + + +@click.command() +@click.argument("profile", required=False) +@click.option("--output", "-o", help="Output file (default: stdout)") +@click.option("format", "--format", type=click.Choice(["env", "json", "yaml"]), default="env") +def export(profile: str, output: str, format: str): + """Export environment variables to a file.""" + from env_pro.core.profile import get_active_profile, get_profile_vars + from env_pro.core.encryption import decrypt_value, get_key_from_keyring + import json + + profile = profile or get_active_profile() or "default" + vars = get_profile_vars(profile) + + keyring_key = get_key_from_keyring() + decrypted_vars = {} + + for key, value in vars.items(): + if keyring_key: + try: + decrypted_vars[key] = decrypt_value(value, keyring_key) + except Exception: + decrypted_vars[key] = value + else: + decrypted_vars[key] = value + + if format == "json": + content = json.dumps(decrypted_vars, indent=2) + elif format == "yaml": + import yaml + content = yaml.dump(decrypted_vars) + else: + lines = [f"{k}={v}" for k, v in decrypted_vars.items()] + content = "\n".join(lines) + + if output: + Path(output).write_text(content) + click.echo(f"Exported to {output}") + else: + click.echo(content) + + +@click.command() +def example(): + """Generate .env.example file.""" + from env_pro.core.profile import get_active_profile, get_profile_vars + + profile = get_active_profile() or "default" + vars = get_profile_vars(profile) + + lines = ["# Generated by env-pro", f"# Profile: {profile}", ""] + + for key, value in vars.items(): + if len(value) > 20: + value = "" + lines.append(f"{key}={value}") + + click.echo("\n".join(lines))