|
| 1 | +# _CLI |
| 2 | +### Abstract base class for wrapping a platform-native CLI executable. |
| 3 | + |
| 4 | +> _CLI.new (executableName : Text; controller : 4D.Class) |
| 5 | +
|
| 6 | +| Parameter | Type | | Description | |
| 7 | +| --- | --- | --- | --- | |
| 8 | +| executableName | Text | -> | Base name of the executable (without `.exe` on Windows) | |
| 9 | +| controller | 4D.Class | -> | Class reference for the controller (default: `cs.llama._CLI_Controller`) | |
| 10 | + |
| 11 | +## Description |
| 12 | + |
| 13 | +`_CLI` resolves the platform-specific path to a bundled executable and attaches a controller that manages the underlying `4D.SystemWorker`. It is extended by [`_llama`](_llama.md) and should not be instantiated directly. |
| 14 | + |
| 15 | +### Resolution strategy |
| 16 | + |
| 17 | +On startup the constructor checks for the executable under `/RESOURCES/bin/{platform}/`. If found it stores the full path and calls `chmod +x` on macOS. If not found it falls back to the executable name alone, relying on `$PATH`. |
| 18 | + |
| 19 | +Platform identifiers: |
| 20 | + |
| 21 | +| Platform | Value | |
| 22 | +| --- | --- | |
| 23 | +| macOS (Intel or Apple Silicon) | `macOS` | |
| 24 | +| Windows x64 | `Windows` | |
| 25 | +| Windows ARM | `WindowsARM` | |
| 26 | + |
| 27 | +### Properties (read-only) |
| 28 | + |
| 29 | +| Property | Type | Description | |
| 30 | +| --- | --- | --- | |
| 31 | +| name | Text | Class name | |
| 32 | +| EOL | Text | `\n` on macOS, `\r\n` on Windows | |
| 33 | +| executableName | Text | Resolved executable file name | |
| 34 | +| platform | Text | Platform string (see table above) | |
| 35 | +| currentDirectory | 4D.Folder | Folder containing the executable | |
| 36 | +| executablePath | Text | Full path (or bare name) of the executable | |
| 37 | +| executableFile | 4D.File | `4D.File` reference to the executable | |
| 38 | +| controller | cs.llama._CLI_Controller | Attached controller instance | |
| 39 | + |
| 40 | +### Methods |
| 41 | + |
| 42 | +#### escape (in : Text) → Text |
| 43 | + |
| 44 | +Shell-escapes a string for the current platform. |
| 45 | + |
| 46 | +| Parameter | Type | | Description | |
| 47 | +| --- | --- | --- | --- | |
| 48 | +| in | Text | -> | Raw string to escape | |
| 49 | +| Result | Text | <- | Shell-safe string | |
| 50 | + |
| 51 | +On macOS/zsh the method prefixes each shell metacharacter with `\`. On Windows/cmd.exe it wraps the string in double quotes when any metacharacter (`& | < > ( ) % ^ " space`) is present. |
| 52 | + |
| 53 | +#### expand (in : Object) → Object |
| 54 | + |
| 55 | +Re-creates a `4D.File` or `4D.Folder` from its platform path, ensuring paths obtained on one platform are normalized correctly. |
| 56 | + |
| 57 | +| Parameter | Type | | Description | |
| 58 | +| --- | --- | --- | --- | |
| 59 | +| in | Object | -> | A `4D.File` or `4D.Folder` | |
| 60 | +| Result | Object | <- | New object of the same class using the platform path | |
| 61 | + |
| 62 | +#### quote (in : Text) → Text |
| 63 | + |
| 64 | +Wraps a string in double quotes. Useful when building command strings that must always be quoted regardless of content. |
| 65 | + |
| 66 | +| Parameter | Type | | Description | |
| 67 | +| --- | --- | --- | --- | |
| 68 | +| in | Text | -> | Input text | |
| 69 | +| Result | Text | <- | `"input"` | |
| 70 | + |
| 71 | +## See also |
| 72 | + |
| 73 | +- [`_CLI_Controller`](_CLI_Controller.md) — manages `4D.SystemWorker` execution |
| 74 | +- [`_llama`](_llama.md) — extends `_CLI` for llama.cpp programs |
0 commit comments