Skip to content

MacOSListDirectoryCommand

Base classes

Name Children Inherits
ListDirectoryCommand
anyenv.os_commands.base
Base class for list directory commands.

⋔ Inheritance diagram

graph TD
  3725664569["list_directory.MacOSListDirectoryCommand"]
  4141724308["base.ListDirectoryCommand"]
  925645236["abc.ABC"]
  2751680898["builtins.object"]
  4141724308 --> 3725664569
  925645236 --> 4141724308
  2751680898 --> 925645236

🛈 DocStrings

Bases: ListDirectoryCommand

macOS list directory command implementation.

Source code in src/anyenv/os_commands/list_directory.py
class MacOSListDirectoryCommand(ListDirectoryCommand):
    """macOS list directory command implementation."""

    def create_command(self, path: str = "") -> str:
        """Generate BSD ls command (no --time-style support).

        Args:
            path: Directory path to list

        Returns:
            The ls command string
        """
        cmd = "ls -la"
        return f"{cmd} {sh_path(path)}" if path else cmd

    def parse_command(
        self,
        output: str,
        path: str = "",
    ) -> list[DirectoryEntry]:
        """Parse BSD ls output (same as Unix).

        Args:
            output: Raw ls command output
            path: Base directory path

        Returns:
            List of DirectoryEntry objects
        """
        # BSD ls output format is same as Unix, just different timestamp format
        unix_cmd = UnixListDirectoryCommand()
        return unix_cmd.parse_command(output, path=path)

create_command

create_command(path: str = '') -> str

Generate BSD ls command (no --time-style support).

Parameters:

Name Type Description Default
path str

Directory path to list

''

Returns:

Type Description
str

The ls command string

Source code in src/anyenv/os_commands/list_directory.py
def create_command(self, path: str = "") -> str:
    """Generate BSD ls command (no --time-style support).

    Args:
        path: Directory path to list

    Returns:
        The ls command string
    """
    cmd = "ls -la"
    return f"{cmd} {sh_path(path)}" if path else cmd

parse_command

parse_command(output: str, path: str = '') -> list[DirectoryEntry]

Parse BSD ls output (same as Unix).

Parameters:

Name Type Description Default
output str

Raw ls command output

required
path str

Base directory path

''

Returns:

Type Description
list[DirectoryEntry]

List of DirectoryEntry objects

Source code in src/anyenv/os_commands/list_directory.py
def parse_command(
    self,
    output: str,
    path: str = "",
) -> list[DirectoryEntry]:
    """Parse BSD ls output (same as Unix).

    Args:
        output: Raw ls command output
        path: Base directory path

    Returns:
        List of DirectoryEntry objects
    """
    # BSD ls output format is same as Unix, just different timestamp format
    unix_cmd = UnixListDirectoryCommand()
    return unix_cmd.parse_command(output, path=path)

:fa-brands-github: Show source on GitHub