Platform-Specific Commands
Create commands that behave differently on Linux, macOS, and Windows. Invowk™ automatically selects the right implementation for the current platform.
Supported Platforms
| Value | Description |
|---|---|
linux | Linux distributions |
macos | macOS (Darwin) |
windows | Windows |
Basic Platform Targeting
Restrict an implementation to specific platforms:
{
name: "open-browser"
implementations: [
{
script: "xdg-open http://localhost:3000"
runtimes: [{name: "native"}]
platforms: [{name: "linux"}]
},
{
script: "open http://localhost:3000"
runtimes: [{name: "native"}]
platforms: [{name: "macos"}]
},
{
script: "start http://localhost:3000"
runtimes: [{name: "native"}]
platforms: [{name: "windows"}]
}
]
}
Targeting All Platforms
To target all platforms, list them explicitly:
{
name: "build"
implementations: [{
script: "go build ./..."
runtimes: [{name: "native"}]
platforms: [{name: "linux"}, {name: "macos"}, {name: "windows"}]
}]
}
Unix-Only Commands
Target both Linux and macOS:
{
name: "check-permissions"
implementations: [{
script: """
chmod +x ./scripts/*.sh
ls -la ./scripts/
"""
runtimes: [{name: "native"}]
platforms: [{name: "linux"}, {name: "macos"}]
}]
}
Platform-Specific Environment
Set different environment variables per platform:
{
name: "configure"
implementations: [
// Linux implementation
{
script: "echo \"Config: $CONFIG_PATH\""
runtimes: [{name: "native"}]
platforms: [{name: "linux"}]
env: {
vars: {
CONFIG_PATH: "/etc/myapp/config.yaml"
CACHE_DIR: "/var/cache/myapp"
}
}
},
// macOS implementation
{
script: "echo \"Config: $CONFIG_PATH\""
runtimes: [{name: "native"}]
platforms: [{name: "macos"}]
env: {
vars: {
CONFIG_PATH: "/usr/local/etc/myapp/config.yaml"
CACHE_DIR: "${HOME}/Library/Caches/myapp"
}
}
},
// Windows implementation
{
script: "echo \"Config: %CONFIG_PATH%\""
runtimes: [{name: "native"}]
platforms: [{name: "windows"}]
env: {
vars: {
CONFIG_PATH: "%APPDATA%\\myapp\\config.yaml"
CACHE_DIR: "%LOCALAPPDATA%\\myapp\\cache"
}
}
}
]
}
Cross-Platform Scripts
Write one script that works everywhere:
{
name: "build"
implementations: [
// Unix platforms (same output name)
{
script: "go build -o bin/app ./..."
runtimes: [{name: "native"}]
platforms: [{name: "linux"}, {name: "macos"}]
},
// Windows (different output name)
{
script: "go build -o bin/app.exe ./..."
runtimes: [{name: "native"}]
platforms: [{name: "windows"}]
}
]
}
CUE Templates for Platforms
Use CUE templates to reduce repetition:
// Define platform templates
_linux: {name: "linux"}
_macos: {name: "macos"}
_windows: {name: "windows"}
_unix: [{name: "linux"}, {name: "macos"}]
_all: [{name: "linux"}, {name: "macos"}, {name: "windows"}]
cmds: [
{
name: "clean"
implementations: [
// Unix implementation
{
script: "rm -rf build/"
runtimes: [{name: "native"}]
platforms: _unix
},
// Windows implementation
{
script: "rmdir /s /q build"
runtimes: [{name: "native"}]
platforms: [_windows]
}
]
}
]
Command Listing
The command list shows supported platforms:
Available Commands
(* = default runtime)
From current directory:
build - Build the project [native*] (linux, macos, windows)
clean - Clean artifacts [native*] (linux, macos)
deploy - Deploy to cloud [native*] (linux)
Unsupported Platform Error
Running a command on an unsupported platform shows a clear error:
✗ Host not supported
Command 'deploy' cannot run on this host.
Current host: windows
Supported hosts: linux, macos
This command is only available on the platforms listed above.
Real-World Examples
System Information
{
name: "sysinfo"
implementations: [
{
script: """
echo "Hostname: $(hostname)"
echo "Kernel: $(uname -r)"
echo "Memory: $(free -h | awk '/^Mem:/{print $2}')"
"""
runtimes: [{name: "native"}]
platforms: [{name: "linux"}]
},
{
script: """
echo "Hostname: $(hostname)"
echo "Kernel: $(uname -r)"
echo "Memory: $(sysctl -n hw.memsize | awk '{print $0/1024/1024/1024 "GB"}')"
"""
runtimes: [{name: "native"}]
platforms: [{name: "macos"}]
},
{
script: """
echo Hostname: %COMPUTERNAME%
systeminfo | findstr "Total Physical Memory"
"""
runtimes: [{name: "native"}]
platforms: [{name: "windows"}]
}
]
}
Package Installation
{
name: "install-deps"
implementations: [
{
script: "apt-get install -y build-essential"
runtimes: [{name: "native"}]
platforms: [{name: "linux"}]
},
{
script: "brew install coreutils"
runtimes: [{name: "native"}]
platforms: [{name: "macos"}]
},
{
script: "choco install make"
runtimes: [{name: "native"}]
platforms: [{name: "windows"}]
}
]
}
Best Practices
- Start with cross-platform: Add platform-specific only when needed
- Use environment variables: Abstract platform differences
- Test on all platforms: CI should cover all supported platforms
- Document limitations: Note which platforms are supported
Next Steps
- Interpreters - Use non-shell interpreters
- Working Directory - Control execution location