Skip to content

MacOSEnvVarCommand

Base classes

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

⋔ Inheritance diagram

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

🛈 DocStrings

Bases: EnvVarCommand

macOS environment variable command implementation.

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

    def create_command(self, name: str) -> str:
        """Generate printenv command (same as Unix).

        Args:
            name: Name of environment variable

        Returns:
            The printenv command string
        """
        return f"printenv {sh_quote(name)}"

    def parse_command(self, output: str, exit_code: int = 0) -> str | None:
        """Parse printenv result (same as Unix).

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

        Returns:
            Variable value or None if not set
        """
        if exit_code != 0:
            return None
        return output.rstrip("\n") if output else None

create_command

create_command(name: str) -> str

Generate printenv command (same as Unix).

Parameters:

Name Type Description Default
name str

Name of environment variable

required

Returns:

Type Description
str

The printenv command string

Source code in src/anyenv/os_commands/env_var.py
def create_command(self, name: str) -> str:
    """Generate printenv command (same as Unix).

    Args:
        name: Name of environment variable

    Returns:
        The printenv command string
    """
    return f"printenv {sh_quote(name)}"

parse_command

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

Parse printenv result (same as Unix).

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 printenv result (same as Unix).

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

    Returns:
        Variable value or None if not set
    """
    if exit_code != 0:
        return None
    return output.rstrip("\n") if output else None

:fa-brands-github: Show source on GitHub