## Learning osproc for NexusOS - External Command Execution
## This demonstrates how to run system commands from Nim

import std/osproc
import std/strutils

echo "=== NexusOS osproc Learning Example ==="

# Example 1: Simple command execution
echo "\n1. Running 'uname -a' to get system info:"
let unameResult = execProcess("uname -a")
echo "Result: ", unameResult.strip()

# Example 2: Check if pacman is available (needed for grafting)
echo "\n2. Checking if pacman is available:"
try:
  let pacmanVersion = execProcess("pacman --version")
  echo "Pacman found! Version info:"
  echo pacmanVersion.split('\n')[0]  # First line only
except:
  echo "Pacman not found - we'll need to simulate grafting"

# Example 3: List files in current directory
echo "\n3. Listing current directory contents:"
let lsResult = execProcess("ls -la")
echo lsResult

# Example 4: Create a test directory structure (like /Programs/App/Version)
echo "\n4. Creating NexusOS-style directory structure:"
let testDir = "/tmp/nexusos-test/Programs/TestApp/1.0.0"
let mkdirResult = execProcess("mkdir -p " & testDir)
if mkdirResult.len == 0:  # No output usually means success
  echo "Successfully created: ", testDir

  # Verify it exists
  let verifyResult = execProcess("ls -la /tmp/nexusos-test/Programs/")
  echo "Directory contents:"
  echo verifyResult
else:
  echo "Error creating directory: ", mkdirResult

echo "\n=== osproc learning complete! ==="