opencode.cmd 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. if defined OPENCODE_BIN_PATH (
  4. set "resolved=%OPENCODE_BIN_PATH%"
  5. goto :execute
  6. )
  7. rem Get the directory of this script
  8. set "script_dir=%~dp0"
  9. set "script_dir=%script_dir:~0,-1%"
  10. rem Detect platform and architecture
  11. set "platform=windows"
  12. rem Detect architecture
  13. if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
  14. set "arch=x64"
  15. ) else if "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
  16. set "arch=arm64"
  17. ) else if "%PROCESSOR_ARCHITECTURE%"=="x86" (
  18. set "arch=x86"
  19. ) else (
  20. set "arch=x64"
  21. )
  22. set "name=opencode-!platform!-!arch!"
  23. set "binary=opencode.exe"
  24. rem Search for the binary starting from script location
  25. set "resolved="
  26. set "current_dir=%script_dir%"
  27. :search_loop
  28. set "candidate=%current_dir%\node_modules\%name%\bin\%binary%"
  29. if exist "%candidate%" (
  30. set "resolved=%candidate%"
  31. goto :execute
  32. )
  33. rem Move up one directory
  34. for %%i in ("%current_dir%") do set "parent_dir=%%~dpi"
  35. set "parent_dir=%parent_dir:~0,-1%"
  36. rem Check if we've reached the root
  37. if "%current_dir%"=="%parent_dir%" goto :not_found
  38. set "current_dir=%parent_dir%"
  39. goto :search_loop
  40. :not_found
  41. echo It seems that your package manager failed to install the right version of the opencode CLI for your platform. You can try manually installing the "%name%" package >&2
  42. exit /b 1
  43. :execute
  44. rem Execute the binary with all arguments
  45. "%resolved%" %*