- Add new subcommands: convert, preflight, server, templates, webpage - Migrate config from bin/config.json to ~/.config/mytoolkit - Fix expand_bookmarks to modify writer objects instead of reader - Improve md_to_pdf with CJK bookmark support - Update README and project metadata
68 lines
1.7 KiB
Python
68 lines
1.7 KiB
Python
"""Environment variables management."""
|
|
|
|
import click
|
|
|
|
from bin.config import CONFIG_PATH, config
|
|
|
|
|
|
@click.group(name="env")
|
|
def env_cmd():
|
|
"""Manage environment variables."""
|
|
pass
|
|
|
|
|
|
@env_cmd.command("list")
|
|
def env_list():
|
|
"""List all vars."""
|
|
click.echo(f"Storage: {CONFIG_PATH}")
|
|
vars = config.get_all()
|
|
if not vars:
|
|
click.echo("No vars configured.")
|
|
return
|
|
click.echo()
|
|
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}")
|