Skip to content

WindowsIsFileCommand

Base classes

Name Children Inherits
IsFileCommand
anyenv.os_commands.base
Base class for is file commands.

⋔ Inheritance diagram

graph TD
  3384505164["is_file.WindowsIsFileCommand"]
  153617120["base.IsFileCommand"]
  925645236["abc.ABC"]
  2751680898["builtins.object"]
  153617120 --> 3384505164
  925645236 --> 153617120
  2751680898 --> 925645236

🛈 DocStrings

Bases: IsFileCommand

Windows is file command implementation.

Source code in src/anyenv/os_commands/is_file.py
class WindowsIsFileCommand(IsFileCommand):
    """Windows is file command implementation."""

    def create_command(self, path: str) -> str:
        """Generate PowerShell file test command.

        Args:
            path: Path to test if it's a file

        Returns:
            The PowerShell command string
        """
        return powershell(
            f"$item = Get-Item -LiteralPath {ps_literal(path)} -ErrorAction SilentlyContinue; "
            "$item -ne $null -and -not $item.PSIsContainer"
        )

    def parse_command(
        self,
        output: str,
        exit_code: int = 0,
    ) -> bool:
        """Parse PowerShell file test result.

        Args:
            output: Raw PowerShell command output
            exit_code: Command exit code (ignored)

        Returns:
            True if path is a file, False otherwise
        """
        return output.strip().lower() == "true"

create_command

create_command(path: str) -> str

Generate PowerShell file test command.

Parameters:

Name Type Description Default
path str

Path to test if it's a file

required

Returns:

Type Description
str

The PowerShell command string

Source code in src/anyenv/os_commands/is_file.py
def create_command(self, path: str) -> str:
    """Generate PowerShell file test command.

    Args:
        path: Path to test if it's a file

    Returns:
        The PowerShell command string
    """
    return powershell(
        f"$item = Get-Item -LiteralPath {ps_literal(path)} -ErrorAction SilentlyContinue; "
        "$item -ne $null -and -not $item.PSIsContainer"
    )

parse_command

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

Parse PowerShell file test result.

Parameters:

Name Type Description Default
output str

Raw PowerShell command output

required
exit_code int

Command exit code (ignored)

0

Returns:

Type Description
bool

True if path is a file, False otherwise

Source code in src/anyenv/os_commands/is_file.py
def parse_command(
    self,
    output: str,
    exit_code: int = 0,
) -> bool:
    """Parse PowerShell file test result.

    Args:
        output: Raw PowerShell command output
        exit_code: Command exit code (ignored)

    Returns:
        True if path is a file, False otherwise
    """
    return output.strip().lower() == "true"

:fa-brands-github: Show source on GitHub