Skip to content

EnvCommand

Base classes

Name Children Inherits
SlashedCommand
slashed.commands
Base class for declarative commands.

⋔ Inheritance diagram

graph TD
  3691695235["system.EnvCommand"]
  807245086["commands.SlashedCommand"]
  900363605["base.BaseCommand"]
  925645236["abc.ABC"]
  2751680898["builtins.object"]
  807245086 --> 3691695235
  900363605 --> 807245086
  925645236 --> 900363605
  2751680898 --> 925645236

🛈 DocStrings

Bases: SlashedCommand

Show or set environment variables.

Usage

/env [name] [value]

Without arguments: show all environment variables With name: show specific variable With name and value: set variable

Source code in src/slashed/builtin/system.py
class EnvCommand(SlashedCommand):
    """Show or set environment variables.

    Usage:
      `/env [name] [value]`

    Without arguments: show all environment variables
    With name: show specific variable
    With name and value: set variable
    """

    name = "env"
    category = "system"

    async def execute_command(
        self,
        ctx: CommandContext[Any],
        name: str | None = None,
        value: str | None = None,
    ) -> None:
        """Manage environment variables."""
        if name is None:
            # Show all variables as markdown table
            lines = [
                "## Environment Variables",
                "",
                "| Variable | Value |",
                "|----------|-------|",
            ]
            for key, val in sorted(os.environ.items()):
                # Truncate long values for readability
                display_val = val if len(val) <= 50 else f"{val[:47]}..."  # noqa: PLR2004
                lines.append(f"| `{key}` | `{display_val}` |")
            await ctx.print("\n".join(lines))
        elif value is None:
            # Show specific variable
            if name in os.environ:
                await ctx.print(f"**{name}:** `{os.environ[name]}`")
            else:
                await ctx.print(f"❌ Variable `{name}` not set")
        else:
            # Set variable
            os.environ[name] = value
            await ctx.print(f"✅ Set **{name}** = `{value}`")

execute_command async

execute_command(
    ctx: CommandContext[Any], name: str | None = None, value: str | None = None
) -> None

Manage environment variables.

Source code in src/slashed/builtin/system.py
async def execute_command(
    self,
    ctx: CommandContext[Any],
    name: str | None = None,
    value: str | None = None,
) -> None:
    """Manage environment variables."""
    if name is None:
        # Show all variables as markdown table
        lines = [
            "## Environment Variables",
            "",
            "| Variable | Value |",
            "|----------|-------|",
        ]
        for key, val in sorted(os.environ.items()):
            # Truncate long values for readability
            display_val = val if len(val) <= 50 else f"{val[:47]}..."  # noqa: PLR2004
            lines.append(f"| `{key}` | `{display_val}` |")
        await ctx.print("\n".join(lines))
    elif value is None:
        # Show specific variable
        if name in os.environ:
            await ctx.print(f"**{name}:** `{os.environ[name]}`")
        else:
            await ctx.print(f"❌ Variable `{name}` not set")
    else:
        # Set variable
        os.environ[name] = value
        await ctx.print(f"✅ Set **{name}** = `{value}`")

:fa-brands-github: Show source on GitHub