Skip to content

WindowsEnvVarCommand

Base classes

Name Children Inherits
EnvVarCommand
anyenv.os_commands.base
Base class for environment variable commands.

⋔ Inheritance diagram

graph TD
  4173865771["env_var.WindowsEnvVarCommand"]
  931535557["base.EnvVarCommand"]
  925645236["abc.ABC"]
  2751680898["builtins.object"]
  931535557 --> 4173865771
  925645236 --> 931535557
  2751680898 --> 925645236

🛈 DocStrings

Bases: EnvVarCommand

Windows environment variable command implementation.

Source code in src/anyenv/os_commands/env_var.py
class WindowsEnvVarCommand(EnvVarCommand):
    """Windows environment variable command implementation."""

    def create_command(self, name: str) -> str:
        """Generate PowerShell environment variable command.

        Args:
            name: Name of environment variable

        Returns:
            The PowerShell command string
        """
        return powershell(f"[Environment]::GetEnvironmentVariable({ps_literal(name)})")

    def parse_command(self, output: str, exit_code: int = 0) -> str | None:
        """Parse PowerShell environment variable result.

        Args:
            output: Raw command output
            exit_code: Command exit code

        Returns:
            Variable value or None if not set
        """
        # PowerShell returns empty string for unset variables
        value = output.strip()
        return value if value else None

create_command

create_command(name: str) -> str

Generate PowerShell environment variable command.

Parameters:

Name Type Description Default
name str

Name of environment variable

required

Returns:

Type Description
str

The PowerShell command string

Source code in src/anyenv/os_commands/env_var.py
def create_command(self, name: str) -> str:
    """Generate PowerShell environment variable command.

    Args:
        name: Name of environment variable

    Returns:
        The PowerShell command string
    """
    return powershell(f"[Environment]::GetEnvironmentVariable({ps_literal(name)})")

parse_command

parse_command(output: str, exit_code: int = 0) -> str | None

Parse PowerShell environment variable result.

Parameters:

Name Type Description Default
output str

Raw command output

required
exit_code int

Command exit code

0

Returns:

Type Description
str | None

Variable value or None if not set

Source code in src/anyenv/os_commands/env_var.py
def parse_command(self, output: str, exit_code: int = 0) -> str | None:
    """Parse PowerShell environment variable result.

    Args:
        output: Raw command output
        exit_code: Command exit code

    Returns:
        Variable value or None if not set
    """
    # PowerShell returns empty string for unset variables
    value = output.strip()
    return value if value else None

:fa-brands-github: Show source on GitHub