### PreInstall Hook Function Example Source: https://github.com/version-fox/vfox/blob/main/docs/plugins/create/howto.md Example of the PreInstall hook function, used to provide pre-installation information such as version, download URL, and checksums. This function is required for plugin installation. ```lua function PLUGIN:PreInstall(ctx) --- input parameters local version = ctx.version --- the current version of vfox running local runtimeVersion = ctx.runtimeVersion return { --- sdk version version = "xxx", --- remote URL or local file path [optional] url = "xxx", --- request headers for remote URL [optional] headers = { ["xxx"] = "xxx", }, --- note information [optional] note = "xxx", --- SHA256 checksum [optional] sha256 = "xxx", --- md5 checksum [optional] md5 = "xxx", --- sha1 checksum [optional] sha1 = "xxx", --- sha512 checksum [optional] sha512 = "xxx", --- additional files [optional] addition = { { --- additional file name ! name = "xxx", --- other same as above ... } } } end ``` -------------------------------- ### Quick Install SDK Source: https://github.com/version-fox/vfox/blob/main/docs/usage/core-commands.md Performs a quick installation of an SDK version, skipping interactive prompts. Can be used with '--all' to install all versions from .vfox.toml. ```shell vfox install --yes nodejs@20 ``` ```shell vfox install --yes --all ``` -------------------------------- ### Install a Runtime Version Source: https://github.com/version-fox/vfox/blob/main/README.md Install a specific version of an SDK using the 'vfox install' command, followed by the SDK name and version. ```bash $ vfox install nodejs@21.5.0 ``` -------------------------------- ### Install a Specific SDK Version Source: https://github.com/version-fox/vfox/wiki/Getting-Started Use this command to directly install a specified version of an SDK. The output shows the download and installation progress. ```bash $ vfox install nodejs@20.10.0 Installing nodejs@20.10.0... Downloading... 100% [===========] (6.7 MB/s) Unpacking ${HOME}/.version-fox/cache/node/node-v20.10.0-darwin-x64.tar.gz... Install nodejs@20.10.0 success! Please use vfox use nodejs@20.10.0 to use it. ``` -------------------------------- ### Install vfox using Install Script (Unix-like) Source: https://github.com/version-fox/vfox/blob/main/docs/guides/quick-start.md Use the install script to install vfox on Unix-like systems. ```shell curl -sSL https://raw.githubusercontent.com/version-fox/vfox/main/install.sh | bash ``` -------------------------------- ### Install and Use SDK with vfox Source: https://github.com/version-fox/vfox/blob/main/docs/guides/multi-user-sharing.md Demonstrates adding a plugin, installing an SDK to the shared directory, and setting a personal version choice. ```bash # Add plugin (SDK will be installed to shared directory) vfox add java # Install SDK vfox install java@21 # Set personal version choice (saved in each user's home directory) vfox use -g java@21 ``` -------------------------------- ### List Installed Versions of All SDKs Source: https://github.com/version-fox/vfox/wiki/Getting-Started Provides a comprehensive list of all installed SDKs and their available versions. ```bash $ vfox ls All installed sdk versions └─┬nodejs ├──v8.16.2 └──v20.10.0 └─┬java ├──v8.0.302 └──v11.0.12 ... ``` -------------------------------- ### Install SDK with vfox Source: https://github.com/version-fox/vfox/blob/main/docs/guides/multi-user-sharing.md Installs a specific SDK version. The first user to install an SDK makes it available to all other users in a shared environment. ```bash vfox install java@21 ``` -------------------------------- ### Plugin Hook Flow - Install Source: https://github.com/version-fox/vfox/blob/main/internal/sdk/AGENTS.md Illustrates the sequence of hooks executed during an SDK installation. ```text Install: PreInstall → Download → PostInstall ``` -------------------------------- ### Install SDK Method Signature Source: https://github.com/version-fox/vfox/blob/main/internal/sdk/AGENTS.md This method is responsible for installing an SDK. It calls PreInstall and PostInstall hooks and handles the download process. ```go func (s *SDK) Install(version string) error { // Calls PreInstall hook, downloads, PostInstall hook return nil } ``` -------------------------------- ### Install SDK Version Source: https://github.com/version-fox/vfox/blob/main/docs/usage/core-commands.md Installs a specific version of an SDK and caches it for future use. Supports installing multiple SDKs simultaneously. ```shell vfox install @ ``` ```shell vfox i @ ``` ```shell vfox install nodejs@20 golang ... ``` -------------------------------- ### Install a plugin from a custom source Source: https://github.com/version-fox/vfox/wiki/Getting-Started Install an SDK plugin from a specified URL or local path. This allows for using custom or shared plugins not in the official repository. ```bash $ vfox add --source https://raw.githubusercontent.com/version-fox/version-fox-plugins/main/nodejs/nodejs.lua custom-node Adding plugin from https://raw.githubusercontent.com/version-fox/version-fox-plugins/main/nodejs/nodejs.lua... Checking plugin... Plugin info: Name -> nodejs Author -> Lihan Version -> 0.0.1 Path -> /${HOME}/.version-fox/plugins/custom-node.lua Add custom-node plugin successfully! Please use `vfox install custom-node@` to install the version you need. ``` -------------------------------- ### Install a vfox Plugin Source: https://github.com/version-fox/vfox/blob/main/docs/plugins/available.md Use this command to quickly install any available vfox plugin from the registry. Replace `` with the desired plugin's name. ```shell vfox add ``` -------------------------------- ### Simple Configuration Format Source: https://github.com/version-fox/vfox/blob/main/AGENTS.md Example of a simple vfox configuration for a tool. ```toml [tools] nodejs = "21.5.1" ``` -------------------------------- ### Install a specific Node.js runtime version Source: https://github.com/version-fox/vfox/blob/main/docs/guides/quick-start.md Install a specific version of Node.js using the installed Node.js plugin. ```bash vfox install nodejs@21.5.0 ``` -------------------------------- ### Project-Level Node.js Version Example Source: https://github.com/version-fox/vfox/blob/main/docs/guides/quick-start.md Demonstrates the steps and expected outcomes after executing the project-level version switch command, including symlink creation, PATH update, and configuration file content. ```bash # 1. Execute command $ vfox use -p nodejs@20.9.0 # 2. View created symlink $ ls -la .vfox/sdks/nodejs lrwxr-xr-x 1 user staff nodejs -> /Users/user/.vfox/cache/nodejs/v-20.9.0/nodejs-20.9.0 # 3. View updated PATH $ echo $PATH /project/path/.vfox/sdks/nodejs/bin:/previous/paths:... # ↑ Project-level nodejs at the front # 4. View configuration file $ cat .vfox.toml [tools] nodejs = "20.9.0" # 5. Verify version (using project-level version) $ node -v v20.9.0 ``` -------------------------------- ### Directory Structure for Installed SDKs Source: https://github.com/version-fox/vfox/wiki/Getting-Started Illustrates the unified directory structure where VersionFox installs SDKs, organized by SDK name. ```bash ${HOME}/.version-fox/cache ├── nodejs │ ├── v20.10.0 │ ├── v18.10.0 ├── java │ ├── v11.0.12 │ ├── v8.0.302 .... ``` -------------------------------- ### List available SDK plugins Source: https://github.com/version-fox/vfox/wiki/Getting-Started View a list of all available SDK plugins that can be installed. This command shows the plugin name, version, author, and description. ```bash $ vfox available Name Version Author Description flutter/flutter 0.0.1 Han Li flutter plugin, support for getting stable, dev, beta version java/adoptium-jdk 0.0.1 aooohan Adoptium JDK ... Please use vfox add to install plugin ``` -------------------------------- ### Install a Specific Version of vfox Source: https://github.com/version-fox/vfox/blob/main/docs/guides/quick-start.md Install a specific version of vfox using the install script. ```shell curl -sSL https://raw.githubusercontent.com/version-fox/vfox/main/install.sh | bash -s -- --version 0.5.6 ``` -------------------------------- ### Get Environment Keys for Scope Method Signature Source: https://github.com/version-fox/vfox/blob/main/internal/sdk/AGENTS.md This method retrieves environment variables for a specific scope and SDK version. The returned paths point to symlinks, not actual installation directories. ```go func (s *SDK) EnvKeysForScope(version string, scope string) ([]string, error) { // Returns env vars with paths pointing to symlinks return nil, nil } ``` -------------------------------- ### Install the latest Node.js runtime version Source: https://github.com/version-fox/vfox/blob/main/docs/guides/quick-start.md Install the latest available Node.js version. Use with caution as 'latest' can introduce breaking changes. ```bash vfox install nodejs@latest ``` -------------------------------- ### Install vfox using Scoop (Windows) Source: https://github.com/version-fox/vfox/blob/main/docs/guides/quick-start.md Use this command to install vfox via Scoop on Windows. ```shell scoop install vfox ``` -------------------------------- ### Install vfox using winget (Windows) Source: https://github.com/version-fox/vfox/blob/main/docs/guides/quick-start.md Use this command to install vfox via winget on Windows. ```shell winget install vfox ``` -------------------------------- ### List Installed SDKs Source: https://github.com/version-fox/vfox/blob/main/docs/usage/core-commands.md Displays a list of all installed SDKs. If an SDK name is provided, it lists versions only for that specific SDK. ```shell vfox list [] ``` ```shell vfox ls [] ``` -------------------------------- ### View Specific Version Path Source: https://github.com/version-fox/vfox/blob/main/docs/usage/plugins-commands.md Displays the installation path for a specific version of an installed plugin. ```shell vfox info nodejs@20.0.0 ``` -------------------------------- ### Install vfox on macOS using Homebrew Source: https://github.com/version-fox/vfox/wiki/Getting-Started Use Homebrew to install vfox on macOS. Ensure you have Homebrew installed first. ```bash $ brew tap version-fox/tap $ brew install vfox ``` -------------------------------- ### Install vfox on Linux using APT Source: https://github.com/version-fox/vfox/wiki/Getting-Started Install vfox on Debian-based Linux distributions using the APT package manager. This involves adding a repository and then installing the package. ```bash echo "deb [trusted=yes] https://apt.fury.io/versionfox/ /" | sudo tee /etc/apt/sources.list.d/versionfox.list sudo apt-get update sudo apt-get install vfox ``` -------------------------------- ### List Installed Versions of a Specific SDK Source: https://github.com/version-fox/vfox/wiki/Getting-Started Displays all installed versions for a given SDK, indicating the currently active one. ```bash $ vfox ls nodejs -> 20.10.0 (current) -> 18.10.0 ... ``` -------------------------------- ### View Plugin Information Source: https://github.com/version-fox/vfox/blob/main/docs/usage/plugins-commands.md Retrieves detailed information about an installed plugin, such as its name, version, and installation path. ```shell vfox info nodejs ``` -------------------------------- ### Install a plugin with an alias Source: https://github.com/version-fox/vfox/wiki/Getting-Started Install an SDK plugin from the official repository and assign it a custom alias. This is useful for managing multiple versions or custom naming. ```bash $ vfox add --alias node nodejs/nodejs Adding plugin from https://raw.githubusercontent.com/version-fox/version-fox-plugins/main/nodejs/nodejs.lua... Checking plugin... Plugin info: Name -> nodejs Author -> Lihan Version -> 0.0.1 Path -> /${HOME}/.version-fox/plugins/node.lua Add node plugin successfully! Please use `vfox install node@` to install the version you need. ``` -------------------------------- ### View Available Plugins Source: https://github.com/version-fox/vfox/blob/main/docs/usage/plugins-commands.md Use this command to see a list of all plugins that can be installed with vfox. ```shell vfox available ``` -------------------------------- ### Environment Variable Handling Conventions Source: https://github.com/version-fox/vfox/blob/main/internal/sdk/AGENTS.md Explains how environment variables are handled, differentiating between actual installed paths and symlink paths. ```text EnvKeys() returns actual installed paths EnvKeysForScope() returns paths pointing to symlinks (NOT actual paths) Plugin hook EnvKeys() determines PATH and other environment variables ``` -------------------------------- ### Execute Command with Multiple SDKs Source: https://github.com/version-fox/vfox/blob/main/docs/usage/core-commands.md This example demonstrates executing a command that requires multiple SDKs. SDKs are merged from left to right, with the leftmost SDK having higher priority in case of conflicts. ```shell vfox exec nodejs@24.14.0 golang@1.25.6 -- npm install -g @qwen-code@qwen-code@latest ``` -------------------------------- ### Install vfox using Homebrew (Unix-like) Source: https://github.com/version-fox/vfox/blob/main/docs/guides/quick-start.md Use this command to install vfox via Homebrew on Unix-like systems. ```shell brew install vfox ``` -------------------------------- ### User-local Installation of vfox Source: https://github.com/version-fox/vfox/blob/main/docs/guides/quick-start.md Install vfox to your user directory without sudo privileges. ```shell curl -sSL https://raw.githubusercontent.com/version-fox/vfox/main/install.sh | bash -s -- --user ``` -------------------------------- ### Switch Runtime Version and Verify Source: https://github.com/version-fox/vfox/blob/main/README.md Switch to a specific installed runtime version using 'vfox use' and verify the active version with the SDK's command-line tool. ```bash $ vfox use nodejs@21.5.0 $ node -v ``` -------------------------------- ### Get Dependencies Source: https://github.com/version-fox/vfox/blob/main/AGENTS.md Download dependencies for the project. ```bash go get . ``` -------------------------------- ### Select SDK Version Interactively Source: https://github.com/version-fox/vfox/wiki/Getting-Started Allows interactive selection of an installed SDK version by listing available versions and enabling fuzzy search. ```bash $ vfox use node Please select a version of node [type to search]: 8.16.2 -> 20.10.0 Now using nodejs@20.10.0 ``` -------------------------------- ### Error Wrapping Example Source: https://github.com/version-fox/vfox/blob/main/AGENTS.md Demonstrates proper error wrapping in Go using fmt.Errorf. ```go fmt.Errorf("context: %w", err) ``` -------------------------------- ### Plugin Source Configuration Example Source: https://github.com/version-fox/vfox/blob/main/docs/plugins/create/howto_registry.md Specifies the manifest URL and testing details for a plugin. This file is placed in the 'sources' directory of the registry. ```json { "name": "nodejs", "manifestUrl": "https://github.com/version-fox/vfox-nodejs/releases/download/manifest/manifest.json", "test": { "version": "21.7.1", "check": "node -v", "resultRegx": "v21.7.1" } } ``` -------------------------------- ### String Manipulation Examples Source: https://github.com/version-fox/vfox/blob/main/docs/plugins/library/strings.md Demonstrates common string operations like splitting, checking prefixes and suffixes, trimming, and joining. Ensure the vfox.strings library is required before use. ```lua local strings = require("vfox.strings") local str_parts = strings.split("hello world", " ") print(str_parts[1]) -- hello assert(strings.has_prefix("hello world", "hello"), [[not strings.has_prefix("hello")]]) assert(strings.has_suffix("hello world", "world"), [[not strings.has_suffix("world")]]) assert(strings.trim("hello world", "world") == "hello ", "strings.trim()") assert(strings.contains("hello world", "hello ") == true, "strings.contains()") got = strings.trim_space(tt.input) local str = strings.join({"1",3,"4"},";") assert(str == "1;3;4", "strings.join()") ``` -------------------------------- ### User-local Installation of a Specific vfox Version Source: https://github.com/version-fox/vfox/blob/main/docs/guides/quick-start.md Install a specific version of vfox to your user directory without sudo. ```shell curl -sSL https://raw.githubusercontent.com/version-fox/vfox/main/install.sh | bash -s -- --user --version 0.5.6 ``` -------------------------------- ### Install Plugin from Zip Archive Source: https://github.com/version-fox/vfox/blob/main/docs/plugins/create/howto.md Install a plugin directly from a zip archive using the 'add --source' command. This is useful for testing or distributing specific plugin versions. ```shell vfox add --source https://github.com/version-fox/vfox-nodejs/releases/download/v0.0.5/vfox-nodejs_0.0.5.zip ``` -------------------------------- ### Add Custom Plugin from Source Source: https://github.com/version-fox/vfox/blob/main/docs/usage/plugins-commands.md Installs a plugin from a specified URL or local file path. This is useful for custom or private plugins. ```shell $ vfox add --source https://github.com/version-fox/vfox-nodejs/releases/download/v0.0.5/vfox-nodejs_0.0.5.zip custom-node ``` -------------------------------- ### PATH Priority Example Source: https://github.com/version-fox/vfox/blob/main/docs/guides/quick-start.md Illustrates the order of precedence for runtime executables when multiple versions are available across different scopes. The project-level path has the highest priority. ```bash # Project > Session > Global > System $PWD/.vfox/sdks/nodejs/bin:~/.vfox/tmp//sdks/nodejs/bin:~/.vfox/sdks/nodejs/bin:/usr/bin:... ``` -------------------------------- ### Use a Specific SDK Version Source: https://github.com/version-fox/vfox/wiki/Getting-Started Command to activate a specific installed version of an SDK for use in your current session. ```bash $ vfox use nodejs@20.10.0 Now using nodejs@20.10.0 ``` -------------------------------- ### Add Plugin from Official Repository Source: https://github.com/version-fox/vfox/blob/main/docs/usage/plugins-commands.md Installs a plugin from the official vfox repository. You can specify an alias for the plugin during installation. ```shell $ vfox add --alias node nodejs ``` -------------------------------- ### Search for available SDK versions Source: https://github.com/version-fox/vfox/wiki/Getting-Started Find all available versions for a specific SDK after its plugin has been installed. Allows interactive selection of versions. ```bash $ vfox search nodejs Please select a version of nodejs [type to search]: -> v21.4.0 [npm v10.2.4] ... v20.10.0 (LTS) [npm v10.2.3] v20.9.0 (LTS) [npm v10.1.0] ... v20.1.0 [npm v9.6.4] v20.0.0 [npm v9.6.4] Press ↑/↓ to select and press ←/→ to page, and press Enter to confirm ``` -------------------------------- ### View Current Versions of All SDKs Source: https://github.com/version-fox/vfox/wiki/Getting-Started Displays the currently active version for all installed SDKs. ```bash $ vfox c nodejs -> v20.10.0 java -> v11.0.12 ``` -------------------------------- ### Add an SDK Plugin Source: https://github.com/version-fox/vfox/blob/main/README.md Use the 'vfox add' command to install a plugin for a specific SDK, enabling management of its versions. ```bash $ vfox add nodejs ``` -------------------------------- ### Anti-Pattern: No Incomplete Cleanup Source: https://github.com/version-fox/vfox/blob/main/internal/sdk/AGENTS.md Warns against incomplete cleanup during installation failures, stating that partial directories must be removed. ```text No incomplete cleanup: Install failure must remove partial directories ``` -------------------------------- ### Install vfox on macOS/Linux using curl Source: https://github.com/version-fox/vfox/wiki/Getting-Started Download and install vfox directly using curl if Homebrew is not available. This script is suitable for both macOS and Linux. ```bash $ curl -sSL https://raw.githubusercontent.com/version-fox/vfox/main/install.sh | bash ``` -------------------------------- ### Migrate to Shared vfox Installation (Linux/macOS) Source: https://github.com/version-fox/vfox/blob/main/docs/guides/multi-user-sharing.md Steps to migrate an existing vfox installation to a shared directory on Linux or macOS. This involves creating a shared directory, moving SDKs and plugins, and setting the VFOX_HOME environment variable. ```bash # 1. Create shared directory sudo mkdir -p /opt/vfox sudo groupadd vfox sudo chgrp vfox /opt/vfox sudo chmod 2775 /opt/vfox # 2. Move existing SDK installations and plugins mkdir -p /opt/vfox/cache /opt/vfox/plugins mv ~/.vfox/cache/* /opt/vfox/cache/ mv ~/.vfox/plugins/* /opt/vfox/plugins/ # 3. Set VFOX_HOME export VFOX_HOME=/opt/vfox # 4. Add to shell configuration echo 'export VFOX_HOME=/opt/vfox' >> ~/.bashrc ``` -------------------------------- ### Complex Configuration Format Source: https://github.com/version-fox/vfox/blob/main/AGENTS.md Example of a complex vfox configuration specifying version and vendor. ```toml [tools] java = { version = "21", vendor = "openjdk" } ``` -------------------------------- ### Plugin Manifest Example Source: https://github.com/version-fox/vfox/blob/main/docs/plugins/create/howto_registry.md Defines the metadata for a specific version of a vfox plugin. Ensure all fields are correctly populated. ```json { "downloadUrl": "https://github.com/version-fox/vfox-nodejs/releases/download/v0.0.5/vfox-nodejs_0.0.5.zip", "notes": [], "version": "0.0.5", "homepage": "https://github.com/version-fox/vfox-nodejs", "minRuntimeVersion": "0.2.6", "license": "Apache 2.0", "description": "Node.js runtime environment.", "name": "nodejs" } ``` -------------------------------- ### Add Multiple Plugins Source: https://github.com/version-fox/vfox/blob/main/docs/usage/plugins-commands.md Installs multiple plugins simultaneously from the official repository. Note that the --alias and --source options are not supported when adding multiple plugins. ```shell $ vfox add golang java nodejs ``` -------------------------------- ### Migrate to Shared vfox Installation (Windows) Source: https://github.com/version-fox/vfox/blob/main/docs/guides/multi-user-sharing.md Steps to migrate an existing vfox installation to a shared directory on Windows. This involves creating a shared directory, moving SDKs and plugins, and setting the VFOX_HOME environment variable for the user. ```powershell # 1. Create shared directory and set permissions (can be placed anywhere) $vfoxPath = "D:\vfox" # Modify to your desired path New-Item -ItemType Directory -Path $vfoxPath -Force $acl = Get-Acl $vfoxPath $rule = New-Object System.Security.AccessControl.FileSystemAccessRule( "Users", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow" ) $acl.SetAccessRule($rule) Set-Acl $vfoxPath $acl # 2. Move existing SDK installations and plugins New-Item -ItemType Directory -Path "$vfoxPath\cache\" -Force New-Item -ItemType Directory -Path "$vfoxPath\plugins\" -Force Move-Item -Path "$env:USERPROFILE\.vfox\cache\*" -Destination "$vfoxPath\cache\" -Force Move-Item -Path "$env:USERPROFILE\.vfox\plugins\*" -Destination "$vfoxPath\plugins\" -Force # 3. Set VFOX_HOME environment variable [System.Environment]::SetEnvironmentVariable('VFOX_HOME', $vfoxPath, 'User') # 4. Restart PowerShell or re-login to apply the environment variable ``` -------------------------------- ### Install vfox on Linux using YUM Source: https://github.com/version-fox/vfox/wiki/Getting-Started Install vfox on Red Hat-based Linux distributions using the YUM package manager. This requires configuring a repository file. ```bash echo "[vfox] name=VersionFox Repo baseurl=https://yum.fury.io/versionfox/ enabled=1 gpgcheck=0" | sudo tee /etc/yum.repos.d/trzsz.repo sudo yum install vfox ``` -------------------------------- ### Perform GET Request Source: https://github.com/version-fox/vfox/blob/main/docs/plugins/library/http.md Use this snippet for GET requests that do not involve downloading files. It demonstrates setting custom headers and asserting response properties. ```lua local http = require("http") -- get request, do not use this request to download files!!! local resp, err = http.get({ url = "https://httpbin.org/json", headers = { ['Host'] = "localhost" } }) -- return parameters assert(err == nil) assert(resp.status_code == 200) assert(resp.headers['Content-Type'] == 'application/json') assert(resp.body == 'xxxxx') ``` -------------------------------- ### Format Specific Version Path Output Source: https://github.com/version-fox/vfox/blob/main/docs/usage/plugins-commands.md Customizes the output of 'vfox info' for a specific version using Go templates to display the installation path. ```shell vfox info --format "{{.Path}}" nodejs@20.0.0 ``` -------------------------------- ### Run Build in Maven Environment Source: https://github.com/version-fox/vfox/blob/main/docs/usage/core-commands.md Execute a build command, such as 'mvn clean install', within a specific Maven SDK environment. ```shell vfox exec maven@3.9.1 -- mvn clean install ``` -------------------------------- ### Use Alias 'x' for Exec Source: https://github.com/version-fox/vfox/blob/main/docs/usage/core-commands.md The 'x' command is a shorthand alias for 'exec'. This example shows how to use it to run a Maven build command. ```shell vfox x maven@3.9.1 -- mvn clean ``` -------------------------------- ### Debug Command Examples Source: https://github.com/version-fox/vfox/blob/main/docs/plugins/create/howto.md Use the --debug flag with vfox commands to obtain more detailed log information during plugin development and testing. ```shell vfox --debug install @ ``` ```shell vfox --debug use @ ``` -------------------------------- ### IDE Integration Example (VS Code tasks.json) Source: https://github.com/version-fox/vfox/blob/main/docs/usage/core-commands.md Configure VS Code's tasks.json to use a specific Node.js SDK version for running tasks. This ensures project consistency across different development environments. ```json { "version": "2.0.0", "tasks": [ { "label": "Run with Node.js", "type": "shell", "command": "vfox", "args": ["x", "nodejs@20", "--", "node", "${file}"] } ] } ``` -------------------------------- ### Build Project Source: https://github.com/version-fox/vfox/blob/main/AGENTS.md Build the vfox project using Go. ```bash go build . ``` -------------------------------- ### PreUninstall Hook Example Source: https://github.com/version-fox/vfox/blob/main/docs/plugins/create/howto.md Implement the PreUninstall hook to perform cleanup operations before a plugin is uninstalled. This function receives context information about the main SDK and other SDKs. ```lua function PLUGIN:PreUninstall(ctx) local mainSdkInfo = ctx.main local mainPath = mainSdkInfo.path local mversion = mainSdkInfo.version local mname = mainSdkInfo.name -- Other SDK information, the `addition` field returned in PreInstall, obtained by name local sdkInfo = ctx.sdkInfo['sdk-name'] local path = sdkInfo.path local version = sdkInfo.version local name = sdkInfo.name end ``` -------------------------------- ### Manager Lifecycle and Resource Management Source: https://github.com/version-fox/vfox/blob/main/cmd/AGENTS.md Illustrates the correct way to instantiate and manage the SDK manager. Always ensure 'defer manager.Close()' is used to release resources. ```go manager, err := internal.NewSdkManager() defer manager.Close() // ALWAYS close to release resources ``` -------------------------------- ### VersionFox Plugin Structure and Lifecycle Methods Source: https://github.com/version-fox/vfox/wiki/How-to-write-a-custom-plugin? This Lua script defines the structure and lifecycle methods for a VersionFox plugin. It includes common libraries, runtime environment variables, plugin metadata, and functions for installation, availability checks, and environment configuration. ```lua --- Common libraries provided by VersionFox (optional) local http = require("http") local json = require("json") local html = require("html") --- The following two parameters are injected by VersionFox at runtime --- Operating system type at runtime (Windows, Linux, Darwin) OS_TYPE = "" --- Operating system architecture at runtime (amd64, arm64, etc.) ARCH_TYPE = "" PLUGIN = { --- Plugin name name = "java", --- Plugin author author = "Lihan", --- Plugin version version = "0.0.1", --- Plugin description description = "xxx", -- Update URL updateUrl = "{URL}/sdk.lua", -- minimum compatible vfox version minRuntimeVersion = "0.2.2", } --- Returns some pre-installed information, such as version number, download address, local files, etc. --- If checksum is provided, vfox will automatically check it for you. --- @param ctx table --- @field ctx.version string User-input version --- @return table Version information function PLUGIN:PreInstall(ctx) local version = ctx.version local runtimeVersion = ctx.runtimeVersion return { --- Version number version = "xxx", --- remote URL or local file path [optional] url = "xxx", --- SHA256 checksum [optional] sha256 = "xxx", --- md5 checksum [optional] md5= "xxx", --- sha1 checksum [optional] sha1 = "xxx", --- sha512 checksum [optional] sha512 = "xx", --- additional need files [optional] addition = { { --- additional file name ! name = "xxx", --- remote URL or local file path [optional] url = "xxx", --- SHA256 checksum [optional] sha256 = "xxx", --- md5 checksum [optional] md5= "xxx", --- sha1 checksum [optional] sha1 = "xxx", --- sha512 checksum [optional] sha512 = "xx", } } } end --- Extension point, called after PreInstall, can perform additional operations, --- such as file operations for the SDK installation directory or compile source code --- Currently can be left unimplemented! function PLUGIN:PostInstall(ctx) --- ctx.rootPath SDK installation directory local rootPath = ctx.rootPath local runtimeVersion = ctx.runtimeVersion local sdkInfo = ctx.sdkInfo['sdk-name'] local path = sdkInfo.path local version = sdkInfo.version local name = sdkInfo.name end --- Return all available versions provided by this plugin --- @param ctx table Empty table used as context, for future extension --- @return table Descriptions of available versions and accompanying tool descriptions function PLUGIN:Available(ctx) local runtimeVersion = ctx.runtimeVersion return { { version = "xxxx", note = "LTS", addition = { { name = "npm", version = "8.8.8", } } } } end --- Each SDK may have different environment variable configurations. --- This allows plugins to define custom environment variables (including PATH settings) --- Note: Be sure to distinguish between environment variable settings for different platforms! --- @param ctx table Context information --- @field ctx.path string SDK installation directory function PLUGIN:EnvKeys(ctx) --- this variable is same as ctx.sdkInfo['plugin-name'].path local mainPath = ctx.path local runtimeVersion = ctx.runtimeVersion local sdkInfo = ctx.sdkInfo['sdk-name'] local path = sdkInfo.path local version = sdkInfo.version local name = sdkInfo.name return { { key = "JAVA_HOME", value = mainPath }, { key = "PATH", value = mainPath .. "/bin" } } end ``` -------------------------------- ### Implement PreUse Hook for Version Selection Source: https://github.com/version-fox/vfox/blob/main/docs/plugins/create/howto.md The PreUse hook is called when a user uses `vfox use`. It returns version information entered by the user, allowing vfox to use a new version if provided. It can access installed SDKs, working directory, and scope. ```lua function PLUGIN:PreUse(ctx) local runtimeVersion = ctx.runtimeVersion --- user input version local version = ctx.version --- user current used version local previousVersion = ctx.previousVersion --- installed sdks (keyed by version string) --- For example, if you have version "1.19.2" installed, use: --- local sdkInfo = ctx.installedSdks['1.19.2'] local sdkInfo = ctx.installedSdks[version] local path = sdkInfo.path local name = sdkInfo.name local sdkVersion = sdkInfo.version --- working directory local cwd = ctx.cwd --- user input scope --- could be one of global/project/session local scope = ctx.scope --- return the version information return { version = sdkVersion, } end ``` -------------------------------- ### Update All Installed Plugins Source: https://github.com/version-fox/vfox/blob/main/docs/usage/plugins-commands.md Updates all plugins that have available updates. This ensures you are using the latest versions of your installed tools. ```shell vfox update --all # update all installed plugins ``` -------------------------------- ### Use SDK in Project Scope Source: https://github.com/version-fox/vfox/wiki/About-the-use-of-scope Records the used SDK and its version in the current directory's `.tool-versions` file. Valid in the current directory. ```bash vfox use -p [@] ``` -------------------------------- ### Use SDK in Global Scope Source: https://github.com/version-fox/vfox/wiki/About-the-use-of-scope Records the used SDK and its versions in the `$HOME/.version-fox/` directory. Valid in global scope. ```bash vfox use -g [@] ``` -------------------------------- ### Implement PostInstall Hook for Post-Installation Operations Source: https://github.com/version-fox/vfox/blob/main/docs/plugins/create/howto.md The PostInstall hook is executed after the PreInstall function. It is intended for additional operations like compiling source code. Implement this hook as needed. ```lua function PLUGIN:PostInstall(ctx) --- SDK installation root path local rootPath = ctx.rootPath local runtimeVersion = ctx.runtimeVersion --- Get it from the name returned by PreInstall local sdkInfo = ctx.sdkInfo['sdk-name'] local path = sdkInfo.path local version = sdkInfo.version local name = sdkInfo.name end ``` -------------------------------- ### Navigate to SDK or VFOX_HOME Directory Source: https://github.com/version-fox/vfox/blob/main/docs/usage/core-commands.md Launches a shell within the VFOX_HOME directory or a specific SDK's directory. Use the --plugin option to navigate to the plugin directory. ```shell vfox cd [options] [] ``` -------------------------------- ### Making HTTP GET Requests in Lua Source: https://github.com/version-fox/vfox/wiki/How-to-write-a-custom-plugin? Use the built-in 'http' library to perform GET requests. Ensure the response status code and content type are as expected. ```lua local http = require("http") assert(type(http) == "table") assert(type(http.get) == "function") local resp, err = http.get({ url = "http://ip.jsontest.com/", headers = { ['Host'] = "localhost" } }) assert(err == nil) assert(resp.status_code == 200) assert(resp.headers['Content-Type'] == 'application/json') assert(resp.body == '{"ip": "xxx.xxx.xxx.xxx"}') ``` -------------------------------- ### Use SDK in Session Scope Source: https://github.com/version-fox/vfox/wiki/About-the-use-of-scope Records the used SDK and its version in the `$HOME/.version-fox/temp` directory. Valid in the current shell session. ```bash vfox use -s [@] ``` -------------------------------- ### List Available SDK Versions Method Signature Source: https://github.com/version-fox/vfox/blob/main/internal/sdk/AGENTS.md This method lists all available SDK versions, utilizing file-based caching for efficiency. ```go func (s *SDK) Available(args string) ([]string, error) { // With file-based caching return nil, nil } ``` -------------------------------- ### Uninstall a Specific SDK Version Source: https://github.com/version-fox/vfox/wiki/Getting-Started Removes a specific version of an installed SDK from your system. ```bash $ vfox un nodejs@20.10.0 Uninstall nodejs@20.10.0 success! ``` -------------------------------- ### Remove Installed Plugin Source: https://github.com/version-fox/vfox/blob/main/docs/usage/plugins-commands.md Uninstalls a plugin and all its associated runtime versions. Use with caution as this action is irreversible. ```shell vfox remove ``` -------------------------------- ### Test All Packages Source: https://github.com/version-fox/vfox/blob/main/AGENTS.md Run all tests for the vfox project. ```bash go test ./... ``` -------------------------------- ### View Plugin Information Source: https://github.com/version-fox/vfox/wiki/Getting-Started Retrieves information about a specific SDK plugin. ```bash $ vfox info nodejs ``` -------------------------------- ### Remove vfox Data Directory Source: https://github.com/version-fox/vfox/blob/main/docs/guides/uninstallation.md Completely remove all vfox data, including installed SDKs, plugins, and configuration files. ```shell rm -rf ~/.version-fox ``` -------------------------------- ### Plugin Hook Flow - Use Source: https://github.com/version-fox/vfox/blob/main/internal/sdk/AGENTS.md Illustrates the sequence of hooks executed when using an SDK version. ```text Use: PreUse (version resolution) → CreateSymlinks → SaveConfig ``` -------------------------------- ### Add vfox APT repository (Debian/Ubuntu) Source: https://github.com/version-fox/vfox/blob/main/docs/guides/quick-start.md Configure the APT repository for vfox on Debian or Ubuntu systems. ```shell echo "deb [trusted=yes lang=none] https://apt.fury.io/versionfox/ /" | sudo tee /etc/apt/sources.list.d/versionfox.list sudo apt-get update sudo apt-get install vfox ``` -------------------------------- ### Create Shared Administrator Configuration Source: https://github.com/version-fox/vfox/blob/main/docs/guides/multi-user-sharing.md Creates a shared config.yaml file in the VFOX_HOME directory to set company-level defaults for proxy, registry, and cache. Sets read-only permissions for non-administrators. ```bash # Create shared configuration file sudo tee /opt/vfox/config.yaml > /dev/null < Session > Global return "", nil } ``` -------------------------------- ### Use SDK Version Method Signature Source: https://github.com/version-fox/vfox/blob/main/internal/sdk/AGENTS.md This method is used to activate a specific SDK version for a given scope. It validates hooks, resolves the version, and creates necessary symlinks. ```go func (s *SDK) Use(version string, scope string) error { // Validates hook env, resolves version, creates symlinks return nil } ``` -------------------------------- ### Correct Manager SDK Operations Source: https://github.com/version-fox/vfox/blob/main/AGENTS.md Shows the correct way to handle SDK operations by delegating to the SDK layer. ```go // CORRECT - Delegate to SDK layer sdk, err := manager.LookupSdk("nodejs") if err != nil { // handle error } sdk.Install(version) sdk.CreateSymlinksForScope(version, env.Project) sdk.EnvKeysForScope(version, env.Project) ``` -------------------------------- ### Uninstall SDK Method Signature Source: https://github.com/version-fox/vfox/blob/main/internal/sdk/AGENTS.md This method handles the uninstallation of an SDK. It invokes PreUninstall and PostUninstall hooks and manages directory cleanup. ```go func (s *SDK) Uninstall(version string) error { // Calls PreUninstall hook, removes symlinks, cleans dir return nil } ``` -------------------------------- ### Release with Goreleaser Source: https://github.com/version-fox/vfox/blob/main/AGENTS.md Create a new release of the vfox project using goreleaser. ```bash goreleaser release ``` -------------------------------- ### Implement ParseLegacyFile Hook for Version Parsing Source: https://github.com/version-fox/vfox/blob/main/docs/plugins/create/howto.md The ParseLegacyFile hook parses other configuration files to determine tool versions, such as .nvmrc or .sdkmanrc. It requires the `legacyFilenames` configuration and can access the filename, filepath, parsing strategy, and installed versions. ```lua function PLUGIN:ParseLegacyFile(ctx) local filename = ctx.filename local filepath = ctx.filepath --- Parsing strategy (latest_installed, latest_available, specified) local strategy = ctx.strategy --- Get the list of versions of the current plugin installed local versions = ctx:getInstalledVersions() return { --- need to return the specific version version = "x.y.z" } end ``` -------------------------------- ### Version Resolution Logic Source: https://github.com/version-fox/vfox/blob/main/internal/sdk/AGENTS.md Outlines the steps involved in resolving an SDK version, from exact match to fuzzy matching. ```text 1. Exact match check via `CheckRuntimeExist()` 2. PreUse hook can modify version 3. Fuzzy match (prefix) if no exact match 4. Returns original input if no match found ``` -------------------------------- ### Execute Command with Specified Version Source: https://github.com/version-fox/vfox/blob/main/docs/usage/core-commands.md Use this snippet to run a command using a specific version of an SDK. The command will be executed in an environment where that SDK version is active. ```shell vfox exec nodejs@20.9.0 -- node -v ``` -------------------------------- ### Execute commands with specific vfox tool versions Source: https://github.com/version-fox/vfox/blob/main/docs/guides/faq.md Use 'vfox exec' to run commands within a specific tool version's environment, suitable for non-interactive shells like Docker or CI/CD. Ensure the tool and version are installed. ```bash vfox exec nodejs@24.14.0 -- npm install -g pnpm ``` ```bash vfox exec nodejs@24.14.0 -- bash -lc 'node -v && npm -v' ``` -------------------------------- ### View Current Version of a Specific SDK Source: https://github.com/version-fox/vfox/wiki/Getting-Started Shows the currently active version for a particular SDK. ```bash $ vfox c nodejs -> v20.10.0 ``` -------------------------------- ### Create Shared Directory (Linux/macOS) Source: https://github.com/version-fox/vfox/blob/main/docs/guides/multi-user-sharing.md Creates a shared directory for vfox SDKs and configures group permissions for secure access. Add users to the 'vfox' group to grant them access. ```bash sudo mkdir -p /opt/vfox # Use group permissions (recommended - more secure) sudo groupadd vfox sudo chgrp vfox /opt/vfox sudo chmod 2775 /opt/vfox # Add user to vfox group sudo usermod -a -G vfox username ``` -------------------------------- ### Search for SDKs Source: https://github.com/version-fox/vfox/blob/main/docs/usage/core-commands.md Searches for available versions of a specified SDK. The results are cached by default for 12 hours. ```shell vfox search [...optionArgs] ``` -------------------------------- ### Configure VFOX_HOME for Fish Source: https://github.com/version-fox/vfox/blob/main/docs/guides/multi-user-sharing.md Sets the VFOX_HOME environment variable in ~/.config/fish/config.fish for shared SDK access. Ensure the shared directory exists. ```shell # Add to ~/.config/fish/config.fish mkdir -p /opt/vfox echo 'set -x VFOX_HOME /opt/vfox' >> ~/.config/fish/config.fish source ~/.config/fish/config.fish ``` -------------------------------- ### Update Storage Path via Command Source: https://github.com/version-fox/vfox/blob/main/docs/guides/configuration.md Use the 'vfox config' command to set or view the SDK storage path. ```shell vfox config storage.sdkPath /tmp ``` -------------------------------- ### Tidy Dependencies Source: https://github.com/version-fox/vfox/blob/main/AGENTS.md Update Go module dependencies. ```bash go mod tidy ``` -------------------------------- ### Create Shared Directory (Windows) Source: https://github.com/version-fox/vfox/blob/main/docs/guides/multi-user-sharing.md Creates a shared directory for vfox SDKs on Windows and sets full control permissions for all users. ```powershell # Create shared directory (can be placed anywhere, e.g., D:\vfox, E:\shared\vfox, etc.) $vfoxPath = "D:\vfox" # Modify to your desired path New-Item -ItemType Directory -Path $vfoxPath -Force # Set full permissions for all users $acl = Get-Acl $vfoxPath $rule = New-Object System.Security.AccessControl.FileSystemAccessRule( "Users", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow" ) $acl.SetAccessRule($rule) Set-Acl $vfoxPath $acl ``` -------------------------------- ### Anti-Pattern: Unlimited Package Path Source: https://github.com/version-fox/vfox/blob/main/internal/plugin/AGENTS.md Advises against using an unrestricted package path, recommending LimitPackagePath() for security and scope control. ```text 2. **Unlimited package path:** Use LimitPackagePath() to restrict module search scope ``` -------------------------------- ### Format Plugin Info Output Source: https://github.com/version-fox/vfox/blob/main/docs/usage/plugins-commands.md Customizes the output of the 'vfox info' command using Go templates to display specific fields like Homepage. ```shell vfox info --format "{{.Homepage}}" nodejs ``` -------------------------------- ### Download File Source: https://github.com/version-fox/vfox/blob/main/docs/plugins/library/http.md Available in vfox >= 0.4.0, this snippet demonstrates downloading a file from a URL to a specified local path. It asserts that no error occurred during the download. ```lua err = http.download_file({ url = "https://version-fox.github.io/vfox-plugins/index.json", headers = {} }, "/usr/local/file") assert(err == nil, [[must be nil]] ) ``` -------------------------------- ### vfox CLI Command Reference Source: https://github.com/version-fox/vfox/blob/main/docs/usage/all-commands.md This is a reference of all available commands for the vfox CLI, including their syntax and a brief description of their functionality. ```shell vfox - vfox is a tool for runtime version management. vfox available List all available plugins vfox add [--alias --source ] Add a plugin or plugins from official repository or custom source, --alias` and `--source` are not supported when adding multiple plugins. vfox remove Remove a plugin vfox update [ | --all] Update a specified or all plugin(s) vfox info [@] [options] Show plugin info or SDK path with optional formatting vfox search Search available versions of a SDK vfox install @ Install the specified version of SDK vfox uninstall @ Uninstall the specified version of SDK vfox use [--global --project --session] [@] Use the specified version of SDK for different scope vfox unuse [--global --project --session] Unset the version of SDK from specified scope vfox exec [@]... -- [args...] Execute a command in vfox managed environment vfox list [] List all installed versions of SDK vfox current [] Show the current version of SDK vfox config [] [] Setup, view config vfox cd [--plugin] [] Launch a shell in the VFOX_HOME, SDK directory, or plugin directory vfox upgrade Upgrade vfox to the latest version vfox help Show this help message ``` -------------------------------- ### Plugin Hook Flow - Uninstall Source: https://github.com/version-fox/vfox/blob/main/internal/sdk/AGENTS.md Illustrates the sequence of hooks executed during an SDK uninstallation. ```text Uninstall: PreUninstall → Remove directory ``` -------------------------------- ### Uninstall vfox via APT Source: https://github.com/version-fox/vfox/blob/main/docs/guides/uninstallation.md Use APT to uninstall the vfox binary and optionally remove the repository configuration. ```shell sudo apt-get remove vfox ``` ```shell sudo rm /etc/apt/sources.list.d/versionfox.list ``` -------------------------------- ### Symlink Creation Convention Source: https://github.com/version-fox/vfox/blob/main/internal/sdk/AGENTS.md Details the process of creating symlinks, including checks for existing symlinks and using a helper function for atomic creation. ```text Check if symlink exists and points to correct target before recreating Use `env.CreateDirSymlink()` which handles old symlink removal Create for both main runtime and all additions ``` -------------------------------- ### Add a vfox plugin Source: https://github.com/version-fox/vfox/blob/main/docs/guides/quick-start.md Use this command to add a plugin for managing a specific runtime, like Node.js. ```bash vfox add nodejs ``` -------------------------------- ### Anti-Pattern: Excessive Network Requests Source: https://github.com/version-fox/vfox/blob/main/internal/plugin/AGENTS.md Advises against making redundant HTTP calls during plugin initialization, suggesting the use of available SDK information instead. ```text 2. **Excessive network requests:** PreInstall should use available SDK info, not make redundant HTTP calls ``` -------------------------------- ### Create Symlinks for Scope Method Signature Source: https://github.com/version-fox/vfox/blob/main/internal/sdk/AGENTS.md This method creates symlinks for a specific SDK version within a given scope. It ensures that symlinks point to the correct target. ```go func (s *SDK) CreateSymlinksForScope(version string, scope string) error { // Creates symlinks in scope-specific directory return nil } ``` -------------------------------- ### Test with Coverage Source: https://github.com/version-fox/vfox/blob/main/AGENTS.md Run tests and generate a coverage profile for the vfox project. ```bash go test ./... -coverprofile=coverage.out -covermode=atomic ``` -------------------------------- ### Test Single Package Source: https://github.com/version-fox/vfox/blob/main/AGENTS.md Run tests for a specific package, such as the internal SDK package. ```bash go test ./internal/sdk -v ```