os_commands
Class info¶
Re-exported classes¶
| Class | Module | Description |
|---|---|---|
| Base64EncodeCommand | anyenv.os_commands.base | Base class for base64 encode commands. |
| CommandBatch | anyenv.os_commands.batch | Batch multiple commands into a single shell call. |
| CommandResult | anyenv.os_commands.models | Base command result model. |
| CopyPathCommand | anyenv.os_commands.base | Base class for copy path commands. |
| CreateDirectoryCommand | anyenv.os_commands.base | Base class for create directory commands. |
| CreateDirectoryResult | anyenv.os_commands.models | Result for directory creation commands. |
| DirectoryEntry | anyenv.os_commands.models | Directory entry model for detailed listings. |
| EnvVarCommand | anyenv.os_commands.base | Base class for environment variable commands. |
| ExistsCommand | anyenv.os_commands.base | Base class for exists commands. |
| ExistsResult | anyenv.os_commands.models | Result for existence check commands. |
| FileInfo | anyenv.os_commands.models | File information model. |
| FileInfoCommand | anyenv.os_commands.base | Base class for file info commands. |
| FindCommand | anyenv.os_commands.base | Base class for recursive find commands. |
| IsDirectoryCommand | anyenv.os_commands.base | Base class for is directory commands. |
| IsFileCommand | anyenv.os_commands.base | Base class for is file commands. |
| ListDirectoryCommand | anyenv.os_commands.base | Base class for list directory commands. |
| MacOSBase64EncodeCommand | anyenv.os_commands.base64_encode | macOS base64 encode command implementation. |
| MacOSCommandProvider | anyenv.os_commands.providers | macOS command provider using BSD tools. |
| MacOSCopyPathCommand | anyenv.os_commands.copy_path | macOS copy path command implementation. |
| MacOSCreateDirectoryCommand | anyenv.os_commands.create_directory | macOS create directory command implementation. |
| MacOSEnvVarCommand | anyenv.os_commands.env_var | macOS environment variable command implementation. |
| MacOSExistsCommand | anyenv.os_commands.exists | macOS exists command implementation. |
| MacOSFileInfoCommand | anyenv.os_commands.file_info | macOS file info command implementation using ls -la. |
| MacOSFindCommand | anyenv.os_commands.find | macOS find command implementation (BSD find). |
| MacOSIsDirectoryCommand | anyenv.os_commands.is_directory | macOS is directory command implementation. |
| MacOSIsFileCommand | anyenv.os_commands.is_file | macOS is file command implementation. |
| MacOSListDirectoryCommand | anyenv.os_commands.list_directory | macOS list directory command implementation. |
| MacOSPwdCommand | anyenv.os_commands.pwd | macOS pwd command implementation. |
| MacOSRemovePathCommand | anyenv.os_commands.remove_path | macOS remove path command implementation. |
| MacOSWhichCommand | anyenv.os_commands.which | macOS which command implementation. |
| OSCommandProvider | anyenv.os_commands.providers | Base class for OS-specific command providers using command classes. |
| PwdCommand | anyenv.os_commands.base | Base class for pwd (print working directory) commands. |
| RemovePathCommand | anyenv.os_commands.base | Base class for remove path commands. |
| RemovePathResult | anyenv.os_commands.models | Result for path removal commands. |
| UnixBase64EncodeCommand | anyenv.os_commands.base64_encode | Unix/Linux base64 encode command implementation. |
| UnixCommandProvider | anyenv.os_commands.providers | Unix/Linux command provider using GNU/POSIX tools. |
| UnixCopyPathCommand | anyenv.os_commands.copy_path | Unix/Linux copy path command implementation. |
| UnixCreateDirectoryCommand | anyenv.os_commands.create_directory | Unix/Linux create directory command implementation. |
| UnixEnvVarCommand | anyenv.os_commands.env_var | Unix/Linux environment variable command implementation. |
| UnixExistsCommand | anyenv.os_commands.exists | Unix/Linux exists command implementation. |
| UnixFileInfoCommand | anyenv.os_commands.file_info | Unix/Linux file info command implementation using ls -la. |
| UnixFindCommand | anyenv.os_commands.find | Unix/Linux find command implementation. |
| UnixIsDirectoryCommand | anyenv.os_commands.is_directory | Unix/Linux is directory command implementation. |
| UnixIsFileCommand | anyenv.os_commands.is_file | Unix/Linux is file command implementation. |
| UnixListDirectoryCommand | anyenv.os_commands.list_directory | Unix/Linux list directory command implementation. |
| UnixPwdCommand | anyenv.os_commands.pwd | Unix/Linux pwd command implementation. |
| UnixRemovePathCommand | anyenv.os_commands.remove_path | Unix/Linux remove path command implementation. |
| UnixWhichCommand | anyenv.os_commands.which | Unix/Linux which command implementation. |
| WhichCommand | anyenv.os_commands.base | Base class for which/where commands to locate executables. |
| WindowsBase64EncodeCommand | anyenv.os_commands.base64_encode | Windows base64 encode command implementation using PowerShell. |
| WindowsCommandProvider | anyenv.os_commands.providers | Windows command provider using PowerShell and CMD. |
| WindowsCopyPathCommand | anyenv.os_commands.copy_path | Windows copy path command implementation. |
| WindowsCreateDirectoryCommand | anyenv.os_commands.create_directory | Windows create directory command implementation. |
| WindowsEnvVarCommand | anyenv.os_commands.env_var | Windows environment variable command implementation. |
| WindowsExistsCommand | anyenv.os_commands.exists | Windows exists command implementation. |
| WindowsFileInfoCommand | anyenv.os_commands.file_info | Windows file info command implementation. |
| WindowsFindCommand | anyenv.os_commands.find | Windows find command implementation using PowerShell. |
| WindowsIsDirectoryCommand | anyenv.os_commands.is_directory | Windows is directory command implementation. |
| WindowsIsFileCommand | anyenv.os_commands.is_file | Windows is file command implementation. |
| WindowsListDirectoryCommand | anyenv.os_commands.list_directory | Windows list directory command implementation. |
| WindowsPwdCommand | anyenv.os_commands.pwd | Windows pwd command implementation. |
| WindowsRemovePathCommand | anyenv.os_commands.remove_path | Windows remove path command implementation. |
| WindowsWhichCommand | anyenv.os_commands.which | Windows where command implementation. |
🛈 DocStrings¶
OS-specific terminal command abstractions for cross-platform filesystem operations.
This package provides a clean abstraction layer for executing OS-specific terminal commands across Unix/Linux, macOS, and Windows platforms. Commands are grouped by OS and individual command types for better organization and maintainability.
Base64EncodeCommand
¶
Bases: ABC
Base class for base64 encode commands.
Source code in src/anyenv/os_commands/base.py
create_command
abstractmethod
¶
CommandBatch
dataclass
¶
Batch multiple commands into a single shell call.
This class allows you to combine multiple OS commands into a single shell invocation, reducing round-trips when commands are executed over a protocol (SSH, containers, etc.).
Example
provider = get_os_command_provider() which_cmd = provider.get_command("which") exists_cmd = provider.get_command("exists")
batch = CommandBatch() batch.add(which_cmd, "python") batch.add(which_cmd, "node") batch.add(exists_cmd, "/tmp/test.txt")
Execute single combined command¶
combined = batch.create_batch_command() result = subprocess.run(combined, shell=True, capture_output=True, text=True)
Parse back to individual results¶
python_path, node_path, exists = batch.parse_batch_output(result.stdout)
Source code in src/anyenv/os_commands/batch.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
__len__
¶
add
¶
add(command: CommandProtocol, *args: Any, **kwargs: Any) -> CommandBatch
Add a command with its arguments to the batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
CommandProtocol
|
The command instance (e.g., WhichCommand, ExistsCommand) |
required |
*args
|
Any
|
Positional arguments to pass to create_command |
()
|
**kwargs
|
Any
|
Keyword arguments to pass to create_command |
{}
|
Returns:
| Type | Description |
|---|---|
CommandBatch
|
Self for method chaining |
Source code in src/anyenv/os_commands/batch.py
clear
¶
create_batch_command
¶
Generate the combined shell command string.
Returns:
| Type | Description |
|---|---|
str
|
A single shell command that executes all batched commands |
str
|
and captures their individual outputs and exit codes. |
Source code in src/anyenv/os_commands/batch.py
parse_batch_output
¶
Parse the combined output back to individual command results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
The raw output from executing the batch command |
required |
Returns:
| Type | Description |
|---|---|
list[Any]
|
List of parsed results, one per command in the batch, |
list[Any]
|
in the same order they were added. |
Source code in src/anyenv/os_commands/batch.py
CommandResult
dataclass
¶
CopyPathCommand
¶
Bases: ABC
Base class for copy path commands.
Source code in src/anyenv/os_commands/base.py
create_command
abstractmethod
¶
Generate copy command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Source path to copy from |
required |
destination
|
str
|
Destination path to copy to |
required |
recursive
|
bool
|
Whether to copy directories recursively |
False
|
Source code in src/anyenv/os_commands/base.py
parse_command
abstractmethod
¶
Parse copy result.
Returns:
| Type | Description |
|---|---|
bool
|
True if copy was successful, False otherwise |
CreateDirectoryCommand
¶
Bases: ABC
Base class for create directory commands.
Source code in src/anyenv/os_commands/base.py
create_command
abstractmethod
¶
CreateDirectoryResult
dataclass
¶
DirectoryEntry
dataclass
¶
Directory entry model for detailed listings.
Source code in src/anyenv/os_commands/models.py
EnvVarCommand
¶
Bases: ABC
Base class for environment variable commands.
Source code in src/anyenv/os_commands/base.py
ExistsCommand
¶
Bases: ABC
Base class for exists commands.
Source code in src/anyenv/os_commands/base.py
create_command
abstractmethod
¶
ExistsResult
dataclass
¶
FileInfo
dataclass
¶
File information model.
Source code in src/anyenv/os_commands/models.py
FileInfoCommand
¶
Bases: ABC
Base class for file info commands.
Source code in src/anyenv/os_commands/base.py
create_command
abstractmethod
¶
FindCommand
¶
Bases: ABC
Base class for recursive find commands.
Used for efficiently finding files/directories recursively in a single command, rather than walking the tree with multiple list operations.
Source code in src/anyenv/os_commands/base.py
create_command
abstractmethod
¶
create_command(
path: str,
pattern: str | None = None,
maxdepth: int | None = None,
file_type: Literal["file", "directory", "all"] = "all",
with_stats: bool = True,
) -> str
Generate recursive find command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Directory to search in |
required |
pattern
|
str | None
|
Glob pattern for name matching (e.g., "*.py") |
None
|
maxdepth
|
int | None
|
Maximum directory depth to descend (None for unlimited) |
None
|
file_type
|
Literal['file', 'directory', 'all']
|
Filter by type - files only, directories only, or all |
'all'
|
with_stats
|
bool
|
Include file stats (size, mtime, type, permissions) |
True
|
Source code in src/anyenv/os_commands/base.py
parse_command
abstractmethod
¶
parse_command(output: str, base_path: str = '') -> list[DirectoryEntry]
Parse find output into DirectoryEntry objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output |
required |
base_path
|
str
|
Base path used in the find command |
''
|
Returns:
| Type | Description |
|---|---|
list[DirectoryEntry]
|
List of DirectoryEntry objects for found items |
Source code in src/anyenv/os_commands/base.py
IsDirectoryCommand
¶
Bases: ABC
Base class for is directory commands.
Source code in src/anyenv/os_commands/base.py
create_command
abstractmethod
¶
IsFileCommand
¶
Bases: ABC
Base class for is file commands.
Source code in src/anyenv/os_commands/base.py
create_command
abstractmethod
¶
ListDirectoryCommand
¶
Bases: ABC
Base class for list directory commands.
Source code in src/anyenv/os_commands/base.py
create_command
abstractmethod
¶
parse_command
abstractmethod
¶
parse_command(output: str, path: str = '') -> list[DirectoryEntry]
MacOSBase64EncodeCommand
¶
Bases: Base64EncodeCommand
macOS base64 encode command implementation.
Source code in src/anyenv/os_commands/base64_encode.py
create_command
¶
Generate macOS base64 command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to file to encode |
required |
Returns:
| Type | Description |
|---|---|
str
|
The base64 command string |
Source code in src/anyenv/os_commands/base64_encode.py
parse_command
¶
Parse macOS base64 output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw base64 encoded output |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
Decoded bytes |
Source code in src/anyenv/os_commands/base64_encode.py
MacOSCommandProvider
¶
Bases: OSCommandProvider
macOS command provider using BSD tools.
Source code in src/anyenv/os_commands/providers.py
__init__
¶
Initialize macOS command provider with macOS command instances.
Source code in src/anyenv/os_commands/providers.py
MacOSCopyPathCommand
¶
Bases: CopyPathCommand
macOS copy path command implementation.
Source code in src/anyenv/os_commands/copy_path.py
create_command
¶
Generate cp command (same as Unix).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Source path to copy from |
required |
destination
|
str
|
Destination path to copy to |
required |
recursive
|
bool
|
Whether to copy directories recursively |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The cp command string |
Source code in src/anyenv/os_commands/copy_path.py
parse_command
¶
Parse cp result based on exit code (same as Unix).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output (ignored) |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if copy was successful, False otherwise |
Source code in src/anyenv/os_commands/copy_path.py
MacOSCreateDirectoryCommand
¶
Bases: CreateDirectoryCommand
macOS create directory command implementation.
Source code in src/anyenv/os_commands/create_directory.py
create_command
¶
Generate mkdir command (same as Unix).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Directory path to create |
required |
parents
|
bool
|
Whether to create parent directories |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The mkdir command string |
Source code in src/anyenv/os_commands/create_directory.py
parse_command
¶
Parse mkdir result based on exit code (same as Unix).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output (ignored) |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if directory was created successfully, False otherwise |
Source code in src/anyenv/os_commands/create_directory.py
MacOSEnvVarCommand
¶
Bases: EnvVarCommand
macOS environment variable command implementation.
Source code in src/anyenv/os_commands/env_var.py
create_command
¶
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 |
parse_command
¶
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
MacOSExistsCommand
¶
Bases: ExistsCommand
macOS exists command implementation.
Source code in src/anyenv/os_commands/exists.py
create_command
¶
Generate test -e command (same as Unix).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to test for existence |
required |
Returns:
| Type | Description |
|---|---|
str
|
The test command string |
parse_command
¶
Parse test result based on exit code (same as Unix).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output (ignored) |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if path exists, False otherwise |
Source code in src/anyenv/os_commands/exists.py
MacOSFileInfoCommand
¶
Bases: FileInfoCommand
macOS file info command implementation using ls -la.
Source code in src/anyenv/os_commands/file_info.py
create_command
¶
Generate ls -la command for file info.
Uses ls -la instead of stat to avoid shell expansion issues with format specifiers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to get information about |
required |
Returns:
| Type | Description |
|---|---|
str
|
The ls command string |
Source code in src/anyenv/os_commands/file_info.py
parse_command
¶
parse_command(output: str, path: str) -> FileInfo
Parse ls -la output for a single file/directory.
BSD ls output format is same as Unix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw ls -la command output |
required |
path
|
str
|
Original path requested |
required |
Returns:
| Type | Description |
|---|---|
FileInfo
|
FileInfo object with parsed information |
Source code in src/anyenv/os_commands/file_info.py
MacOSFindCommand
¶
Bases: FindCommand
macOS find command implementation (BSD find).
Source code in src/anyenv/os_commands/find.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
create_command
¶
create_command(
path: str,
pattern: str | None = None,
maxdepth: int | None = None,
file_type: Literal["file", "directory", "all"] = "all",
with_stats: bool = True,
) -> str
Generate macOS find command.
BSD find doesn't support -printf, so we use -exec stat for file stats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Directory to search in |
required |
pattern
|
str | None
|
Glob pattern for name matching (e.g., "*.py") |
None
|
maxdepth
|
int | None
|
Maximum directory depth to descend |
None
|
file_type
|
Literal['file', 'directory', 'all']
|
Filter by type - files only, directories only, or all |
'all'
|
with_stats
|
bool
|
Include file stats (uses -exec stat, slower than GNU -printf) |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The find command string |
Source code in src/anyenv/os_commands/find.py
parse_command
¶
parse_command(output: str, base_path: str = '') -> list[DirectoryEntry]
Parse macOS find output.
Handles both plain path output and stat-formatted output with stats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw find command output |
required |
base_path
|
str
|
Base path used in the find command |
''
|
Returns:
| Type | Description |
|---|---|
list[DirectoryEntry]
|
List of DirectoryEntry objects |
Source code in src/anyenv/os_commands/find.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
MacOSIsDirectoryCommand
¶
Bases: IsDirectoryCommand
macOS is directory command implementation.
Source code in src/anyenv/os_commands/is_directory.py
create_command
¶
Generate test -d command (same as Unix).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to test if it's a directory |
required |
Returns:
| Type | Description |
|---|---|
str
|
The test command string |
parse_command
¶
Parse test -d result based on exit code (same as Unix).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output (ignored) |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if path is a directory, False otherwise |
Source code in src/anyenv/os_commands/is_directory.py
MacOSIsFileCommand
¶
Bases: IsFileCommand
macOS is file command implementation.
Source code in src/anyenv/os_commands/is_file.py
create_command
¶
Generate test -f command (same as Unix).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to test if it's a file |
required |
Returns:
| Type | Description |
|---|---|
str
|
The test command string |
parse_command
¶
Parse test -f result based on exit code (same as Unix).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output (ignored) |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if path is a file, False otherwise |
Source code in src/anyenv/os_commands/is_file.py
MacOSListDirectoryCommand
¶
Bases: ListDirectoryCommand
macOS list directory command implementation.
Source code in src/anyenv/os_commands/list_directory.py
create_command
¶
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
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
MacOSPwdCommand
¶
Bases: PwdCommand
macOS pwd command implementation.
Source code in src/anyenv/os_commands/pwd.py
create_command
¶
parse_command
¶
Parse pwd 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
|
Current working directory or None on failure |
Source code in src/anyenv/os_commands/pwd.py
MacOSRemovePathCommand
¶
Bases: RemovePathCommand
macOS remove path command implementation.
Source code in src/anyenv/os_commands/remove_path.py
create_command
¶
Generate rm command (same as Unix).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to remove |
required |
recursive
|
bool
|
Whether to remove directories recursively |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The rm command string |
Source code in src/anyenv/os_commands/remove_path.py
parse_command
¶
Parse rm result based on exit code (same as Unix).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output (ignored) |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if path was removed successfully, False otherwise |
Source code in src/anyenv/os_commands/remove_path.py
MacOSWhichCommand
¶
Bases: WhichCommand
macOS which command implementation.
Source code in src/anyenv/os_commands/which.py
create_command
¶
Generate which command (same as Unix).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executable
|
str
|
Name of executable to find |
required |
Returns:
| Type | Description |
|---|---|
str
|
The which command string |
parse_command
¶
Parse which 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
|
Path to executable or None if not found |
Source code in src/anyenv/os_commands/which.py
OSCommandProvider
¶
Base class for OS-specific command providers using command classes.
Source code in src/anyenv/os_commands/providers.py
__init__
¶
Initialize the command provider with command instances.
Source code in src/anyenv/os_commands/providers.py
get_command
¶
get_command(command_type: Literal['list_directory']) -> ListDirectoryCommand
get_command(command_type: Literal['file_info']) -> FileInfoCommand
get_command(command_type: Literal['exists']) -> ExistsCommand
get_command(command_type: Literal['is_file']) -> IsFileCommand
get_command(command_type: Literal['is_directory']) -> IsDirectoryCommand
get_command(command_type: Literal['create_directory']) -> CreateDirectoryCommand
get_command(command_type: Literal['remove_path']) -> RemovePathCommand
get_command(command_type: Literal['copy_path']) -> CopyPathCommand
get_command(command_type: Literal['base64_encode']) -> Base64EncodeCommand
get_command(command_type: Literal['which']) -> WhichCommand
get_command(command_type: Literal['pwd']) -> PwdCommand
get_command(command_type: Literal['env_var']) -> EnvVarCommand
get_command(command_type: Literal['find']) -> FindCommand
get_command(
command_type: CommandType,
) -> (
ListDirectoryCommand
| FileInfoCommand
| ExistsCommand
| IsFileCommand
| IsDirectoryCommand
| CreateDirectoryCommand
| RemovePathCommand
| CopyPathCommand
| Base64EncodeCommand
| WhichCommand
| PwdCommand
| EnvVarCommand
| FindCommand
)
Get command instance by type.
Source code in src/anyenv/os_commands/providers.py
PwdCommand
¶
Bases: ABC
Base class for pwd (print working directory) commands.
Source code in src/anyenv/os_commands/base.py
RemovePathCommand
¶
Bases: ABC
Base class for remove path commands.
Source code in src/anyenv/os_commands/base.py
create_command
abstractmethod
¶
RemovePathResult
dataclass
¶
UnixBase64EncodeCommand
¶
Bases: Base64EncodeCommand
Unix/Linux base64 encode command implementation.
Source code in src/anyenv/os_commands/base64_encode.py
create_command
¶
Generate Unix base64 command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to file to encode |
required |
Returns:
| Type | Description |
|---|---|
str
|
The base64 command string |
parse_command
¶
Parse Unix base64 output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw base64 encoded output |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
Decoded bytes |
Source code in src/anyenv/os_commands/base64_encode.py
UnixCommandProvider
¶
Bases: OSCommandProvider
Unix/Linux command provider using GNU/POSIX tools.
Source code in src/anyenv/os_commands/providers.py
__init__
¶
Initialize Unix command provider with Unix command instances.
Source code in src/anyenv/os_commands/providers.py
UnixCopyPathCommand
¶
Bases: CopyPathCommand
Unix/Linux copy path command implementation.
Source code in src/anyenv/os_commands/copy_path.py
create_command
¶
Generate Unix cp command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Source path to copy from |
required |
destination
|
str
|
Destination path to copy to |
required |
recursive
|
bool
|
Whether to copy directories recursively |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The cp command string |
Source code in src/anyenv/os_commands/copy_path.py
parse_command
¶
Parse Unix cp result based on exit code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output (ignored) |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if copy was successful, False otherwise |
Source code in src/anyenv/os_commands/copy_path.py
UnixCreateDirectoryCommand
¶
Bases: CreateDirectoryCommand
Unix/Linux create directory command implementation.
Source code in src/anyenv/os_commands/create_directory.py
create_command
¶
Generate Unix mkdir command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Directory path to create |
required |
parents
|
bool
|
Whether to create parent directories |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The mkdir command string |
Source code in src/anyenv/os_commands/create_directory.py
parse_command
¶
Parse Unix mkdir result based on exit code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output (ignored) |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if directory was created successfully, False otherwise |
Source code in src/anyenv/os_commands/create_directory.py
UnixEnvVarCommand
¶
Bases: EnvVarCommand
Unix/Linux environment variable command implementation.
Source code in src/anyenv/os_commands/env_var.py
create_command
¶
Generate Unix printenv command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of environment variable |
required |
Returns:
| Type | Description |
|---|---|
str
|
The printenv command string |
parse_command
¶
Parse Unix printenv 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
UnixExistsCommand
¶
Bases: ExistsCommand
Unix/Linux exists command implementation.
Source code in src/anyenv/os_commands/exists.py
create_command
¶
Generate Unix test -e command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to test for existence |
required |
Returns:
| Type | Description |
|---|---|
str
|
The test command string |
parse_command
¶
Parse Unix test result based on exit code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output (ignored) |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if path exists, False otherwise |
Source code in src/anyenv/os_commands/exists.py
UnixFileInfoCommand
¶
Bases: FileInfoCommand
Unix/Linux file info command implementation using ls -la.
Source code in src/anyenv/os_commands/file_info.py
create_command
¶
Generate ls -la command for file info.
Uses ls -la instead of stat to avoid shell expansion issues with format specifiers like %s, %F, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to get information about |
required |
Returns:
| Type | Description |
|---|---|
str
|
The ls command string |
Source code in src/anyenv/os_commands/file_info.py
parse_command
¶
parse_command(output: str, path: str) -> FileInfo
Parse ls -la output for a single file/directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw ls -la command output |
required |
path
|
str
|
Original path requested |
required |
Returns:
| Type | Description |
|---|---|
FileInfo
|
FileInfo object with parsed information |
Source code in src/anyenv/os_commands/file_info.py
UnixFindCommand
¶
Bases: FindCommand
Unix/Linux find command implementation.
Source code in src/anyenv/os_commands/find.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
create_command
¶
create_command(
path: str,
pattern: str | None = None,
maxdepth: int | None = None,
file_type: Literal["file", "directory", "all"] = "all",
with_stats: bool = True,
) -> str
Generate Unix find command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Directory to search in |
required |
pattern
|
str | None
|
Glob pattern for name matching (e.g., "*.py") |
None
|
maxdepth
|
int | None
|
Maximum directory depth to descend |
None
|
file_type
|
Literal['file', 'directory', 'all']
|
Filter by type - files only, directories only, or all |
'all'
|
with_stats
|
bool
|
Include file stats using -printf (size, mtime, type, perms) |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The find command string |
Source code in src/anyenv/os_commands/find.py
parse_command
¶
parse_command(output: str, base_path: str = '') -> list[DirectoryEntry]
Parse Unix find output.
Handles both plain path output and -printf formatted output with stats. Detects format automatically based on presence of tab separators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw find command output |
required |
base_path
|
str
|
Base path used in the find command |
''
|
Returns:
| Type | Description |
|---|---|
list[DirectoryEntry]
|
List of DirectoryEntry objects |
Source code in src/anyenv/os_commands/find.py
UnixIsDirectoryCommand
¶
Bases: IsDirectoryCommand
Unix/Linux is directory command implementation.
Source code in src/anyenv/os_commands/is_directory.py
create_command
¶
Generate Unix test -d command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to test if it's a directory |
required |
Returns:
| Type | Description |
|---|---|
str
|
The test command string |
parse_command
¶
Parse Unix test -d result based on exit code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output (ignored) |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if path is a directory, False otherwise |
Source code in src/anyenv/os_commands/is_directory.py
UnixIsFileCommand
¶
Bases: IsFileCommand
Unix/Linux is file command implementation.
Source code in src/anyenv/os_commands/is_file.py
create_command
¶
Generate Unix test -f command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to test if it's a file |
required |
Returns:
| Type | Description |
|---|---|
str
|
The test command string |
parse_command
¶
Parse Unix test -f result based on exit code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output (ignored) |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if path is a file, False otherwise |
Source code in src/anyenv/os_commands/is_file.py
UnixListDirectoryCommand
¶
Bases: ListDirectoryCommand
Unix/Linux list directory command implementation.
Source code in src/anyenv/os_commands/list_directory.py
create_command
¶
Generate Unix ls command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Directory path to list |
''
|
Returns:
| Type | Description |
|---|---|
str
|
The ls command string |
parse_command
¶
parse_command(output: str, path: str = '') -> list[DirectoryEntry]
Parse Unix ls output.
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
UnixPwdCommand
¶
Bases: PwdCommand
Unix/Linux pwd command implementation.
Source code in src/anyenv/os_commands/pwd.py
create_command
¶
parse_command
¶
Parse Unix pwd result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
str | None
|
Current working directory or None on failure |
Source code in src/anyenv/os_commands/pwd.py
UnixRemovePathCommand
¶
Bases: RemovePathCommand
Unix/Linux remove path command implementation.
Source code in src/anyenv/os_commands/remove_path.py
create_command
¶
Generate Unix rm command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to remove |
required |
recursive
|
bool
|
Whether to remove directories recursively |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The rm command string |
Source code in src/anyenv/os_commands/remove_path.py
parse_command
¶
Parse Unix rm result based on exit code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output (ignored) |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if path was removed successfully, False otherwise |
Source code in src/anyenv/os_commands/remove_path.py
UnixWhichCommand
¶
Bases: WhichCommand
Unix/Linux which command implementation.
Source code in src/anyenv/os_commands/which.py
create_command
¶
Generate Unix which command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executable
|
str
|
Name of executable to find |
required |
Returns:
| Type | Description |
|---|---|
str
|
The which command string |
parse_command
¶
Parse Unix which result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
str | None
|
Path to executable or None if not found |
Source code in src/anyenv/os_commands/which.py
WhichCommand
¶
Bases: ABC
Base class for which/where commands to locate executables.
Source code in src/anyenv/os_commands/base.py
WindowsBase64EncodeCommand
¶
Bases: Base64EncodeCommand
Windows base64 encode command implementation using PowerShell.
Source code in src/anyenv/os_commands/base64_encode.py
create_command
¶
Generate PowerShell base64 encode command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to file to encode |
required |
Returns:
| Type | Description |
|---|---|
str
|
The PowerShell command string |
Source code in src/anyenv/os_commands/base64_encode.py
parse_command
¶
Parse PowerShell base64 output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw base64 encoded output |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
Decoded bytes |
Source code in src/anyenv/os_commands/base64_encode.py
WindowsCommandProvider
¶
Bases: OSCommandProvider
Windows command provider using PowerShell and CMD.
Source code in src/anyenv/os_commands/providers.py
__init__
¶
Initialize Windows command provider with Windows command instances.
Source code in src/anyenv/os_commands/providers.py
WindowsCopyPathCommand
¶
Bases: CopyPathCommand
Windows copy path command implementation.
Source code in src/anyenv/os_commands/copy_path.py
create_command
¶
Generate Windows copy command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Source path to copy from |
required |
destination
|
str
|
Destination path to copy to |
required |
recursive
|
bool
|
Whether to copy directories recursively |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The copy command string |
Source code in src/anyenv/os_commands/copy_path.py
parse_command
¶
Parse Windows copy result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output (ignored) |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if copy was successful, False otherwise |
Source code in src/anyenv/os_commands/copy_path.py
WindowsCreateDirectoryCommand
¶
Bases: CreateDirectoryCommand
Windows create directory command implementation.
Source code in src/anyenv/os_commands/create_directory.py
create_command
¶
Generate Windows directory creation command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Directory path to create |
required |
parents
|
bool
|
Whether to create parent directories |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The directory creation command string |
Source code in src/anyenv/os_commands/create_directory.py
parse_command
¶
Parse Windows directory creation result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output (ignored) |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if directory was created successfully, False otherwise |
Source code in src/anyenv/os_commands/create_directory.py
WindowsEnvVarCommand
¶
Bases: EnvVarCommand
Windows environment variable command implementation.
Source code in src/anyenv/os_commands/env_var.py
create_command
¶
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
parse_command
¶
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
WindowsExistsCommand
¶
Bases: ExistsCommand
Windows exists command implementation.
Source code in src/anyenv/os_commands/exists.py
create_command
¶
Generate PowerShell Test-Path command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to test for existence |
required |
Returns:
| Type | Description |
|---|---|
str
|
The PowerShell command string |
Source code in src/anyenv/os_commands/exists.py
parse_command
¶
Parse PowerShell Test-Path 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 exists, False otherwise |
Source code in src/anyenv/os_commands/exists.py
WindowsFileInfoCommand
¶
Bases: FileInfoCommand
Windows file info command implementation.
Source code in src/anyenv/os_commands/file_info.py
create_command
¶
Generate PowerShell file info command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to get information about |
required |
Returns:
| Type | Description |
|---|---|
str
|
The PowerShell command string |
Source code in src/anyenv/os_commands/file_info.py
parse_command
¶
parse_command(output: str, path: str) -> FileInfo
Parse PowerShell output format: name||size||type||mtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw PowerShell command output |
required |
path
|
str
|
Original path requested |
required |
Returns:
| Type | Description |
|---|---|
FileInfo
|
FileInfo object with parsed information |
Source code in src/anyenv/os_commands/file_info.py
WindowsFindCommand
¶
Bases: FindCommand
Windows find command implementation using PowerShell.
Source code in src/anyenv/os_commands/find.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
create_command
¶
create_command(
path: str,
pattern: str | None = None,
maxdepth: int | None = None,
file_type: Literal["file", "directory", "all"] = "all",
with_stats: bool = True,
) -> str
Generate Windows PowerShell Get-ChildItem command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Directory to search in |
required |
pattern
|
str | None
|
Glob pattern for name matching (e.g., "*.py") |
None
|
maxdepth
|
int | None
|
Maximum directory depth to descend |
None
|
file_type
|
Literal['file', 'directory', 'all']
|
Filter by type - files only, directories only, or all |
'all'
|
with_stats
|
bool
|
Include file stats (always True for Windows, included for API consistency) |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The PowerShell command string |
Source code in src/anyenv/os_commands/find.py
parse_command
¶
parse_command(output: str, base_path: str = '') -> list[DirectoryEntry]
Parse Windows PowerShell Get-ChildItem output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output (path|size|mode per line) |
required |
base_path
|
str
|
Base path used in the command |
''
|
Returns:
| Type | Description |
|---|---|
list[DirectoryEntry]
|
List of DirectoryEntry objects |
Source code in src/anyenv/os_commands/find.py
WindowsIsDirectoryCommand
¶
Bases: IsDirectoryCommand
Windows is directory command implementation.
Source code in src/anyenv/os_commands/is_directory.py
create_command
¶
Generate PowerShell directory test command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to test if it's a directory |
required |
Returns:
| Type | Description |
|---|---|
str
|
The PowerShell command string |
Source code in src/anyenv/os_commands/is_directory.py
parse_command
¶
Parse PowerShell directory 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 directory, False otherwise |
Source code in src/anyenv/os_commands/is_directory.py
WindowsIsFileCommand
¶
Bases: IsFileCommand
Windows is file command implementation.
Source code in src/anyenv/os_commands/is_file.py
create_command
¶
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
parse_command
¶
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
WindowsListDirectoryCommand
¶
Bases: ListDirectoryCommand
Windows list directory command implementation.
Source code in src/anyenv/os_commands/list_directory.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
create_command
¶
Generate Windows PowerShell dir command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Directory path to list |
''
|
Returns:
| Type | Description |
|---|---|
str
|
The PowerShell command string |
Source code in src/anyenv/os_commands/list_directory.py
parse_command
¶
parse_command(output: str, path: str = '') -> list[DirectoryEntry]
Parse Windows PowerShell Get-ChildItem output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw PowerShell 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
WindowsPwdCommand
¶
Bases: PwdCommand
Windows pwd command implementation.
Source code in src/anyenv/os_commands/pwd.py
create_command
¶
Generate Windows cd command (prints current directory when no args).
Returns:
| Type | Description |
|---|---|
str
|
The cd command string |
parse_command
¶
Parse Windows cd result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
str | None
|
Current working directory or None on failure |
Source code in src/anyenv/os_commands/pwd.py
WindowsRemovePathCommand
¶
Bases: RemovePathCommand
Windows remove path command implementation.
Source code in src/anyenv/os_commands/remove_path.py
create_command
¶
Generate Windows removal command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to remove |
required |
recursive
|
bool
|
Whether to remove directories recursively |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The removal command string |
Source code in src/anyenv/os_commands/remove_path.py
parse_command
¶
Parse Windows removal result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output (ignored) |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if path was removed successfully, False otherwise |
Source code in src/anyenv/os_commands/remove_path.py
WindowsWhichCommand
¶
Bases: WhichCommand
Windows where command implementation.
Source code in src/anyenv/os_commands/which.py
create_command
¶
Generate Windows where command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
executable
|
str
|
Name of executable to find |
required |
Returns:
| Type | Description |
|---|---|
str
|
The where command string |
Source code in src/anyenv/os_commands/which.py
parse_command
¶
Parse Windows where result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
Raw command output |
required |
exit_code
|
int
|
Command exit code |
0
|
Returns:
| Type | Description |
|---|---|
str | None
|
Path to first matching executable or None if not found |
Source code in src/anyenv/os_commands/which.py
get_os_command_provider
¶
get_os_command_provider(
system: Literal["Windows", "Darwin", "Linux"] | None = None,
) -> OSCommandProvider
Auto-detect OS and return appropriate command provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
Literal['Windows', 'Darwin', 'Linux'] | None
|
The system to use. If None, the current system is used. |
None
|
Returns:
| Type | Description |
|---|---|
OSCommandProvider
|
OS-specific command provider based on current platform |