- Move all source files from mytoolkit/ to bin/ - Update entry point and build config in pyproject.toml - Add pillow and pypdf dependencies - Update README and .gitignore paths - Remove unused subprocess import in pdf.py - Clean up duplicate imports in pdf merge command
66 lines
1.7 KiB
Python
66 lines
1.7 KiB
Python
"""Environment variables management."""
|
|
|
|
import click
|
|
|
|
from bin.config import config
|
|
|
|
|
|
@click.group(name="env")
|
|
def env_cmd():
|
|
"""Manage environment variables."""
|
|
pass
|
|
|
|
|
|
@env_cmd.command("list")
|
|
def env_list():
|
|
"""List all vars."""
|
|
vars = config.get_all()
|
|
if not vars:
|
|
click.echo("No vars configured.")
|
|
return
|
|
for name, value in sorted(vars.items()):
|
|
masked = "***" if any(x in name.lower() for x in ["key", "secret", "token", "pass"]) else value
|
|
click.echo(f"{name:20} = {masked}")
|
|
|
|
|
|
@env_cmd.command("get")
|
|
@click.argument("name")
|
|
def env_get(name):
|
|
"""Get a var value."""
|
|
value = config.get(name)
|
|
if value is None:
|
|
click.echo(f"Var not found: {name}", err=True)
|
|
raise click.Exit(1)
|
|
click.echo(value)
|
|
|
|
|
|
@env_cmd.command("set")
|
|
@click.argument("name")
|
|
@click.argument("value", required=False)
|
|
@click.option("--secret", is_flag=True, help="Hide input for secrets")
|
|
def env_set(name, value, secret):
|
|
"""Set a var. Prompts if value not provided."""
|
|
if value is None:
|
|
value = click.prompt("Value", hide_input=secret)
|
|
config.set(name, value)
|
|
click.secho(f"Set: {name}", fg="green")
|
|
|
|
|
|
@env_cmd.command("remove")
|
|
@click.argument("name")
|
|
@click.confirmation_option(prompt="Remove this var?")
|
|
def env_remove(name):
|
|
"""Remove a var."""
|
|
if config.remove(name):
|
|
click.secho(f"Removed: {name}", fg="green")
|
|
else:
|
|
click.echo(f"Var not found: {name}", err=True)
|
|
raise click.Exit(1)
|
|
|
|
|
|
@env_cmd.command("export")
|
|
def env_export():
|
|
"""Print export statements for shell eval."""
|
|
for name, value in config.export().items():
|
|
click.echo(f"export {name}={value}")
|