Open enghitalo opened 2 days ago
Something like
#!/bin/bash
# Function to print an error message and exit
function error_exit {
echo "$1" 1>&2
exit 1
}
# Function to get the latest installed version of V
function get_latest_installed_version {
local latest_version=$(ls /usr/lib/v | sort -V | tail -n 1)
if [[ -z "$latest_version" ]]; then
error_exit "No V versions found. Please install V."
fi
echo "$latest_version"
}
# Function to install the specified version of V
function install_v_version {
local version=$1
echo "Installing V version $version..."
wget "https://github.com/vlang/v/releases/download/$version/v_linux.zip" -O /tmp/v-$version.zip
mkdir -p "/usr/lib/v/$version/bin"
unzip -jo /tmp/v-$version.zip v/v -d /usr/lib/v/$version/bin
ln -sf "/usr/lib/v/$version/bin/v" "/usr/local/bin/v$version"
}
# Determine the project directory
PROJECT_DIR=$(pwd)
if [[ -z "$1" ]]; then
error_exit "Please specify a project directory or file."
fi
# Check if the specified argument is a directory or file
if [[ -d "$1" ]]; then
PROJECT_DIR="$1"
elif [[ -f "$1" ]]; then
PROJECT_DIR=$(dirname "$1")
else
error_exit "Invalid project directory or file specified."
fi
# Look for .vvmrc file
VVMRC_FILE="$PROJECT_DIR/.vvmrc"
if [[ -f "$VVMRC_FILE" ]]; then
V_VERSION=$(cat "$VVMRC_FILE" | tr -d '[:space:]')
else
V_VERSION=$(get_latest_installed_version)
fi
# Check if the specified version is installed
if [[ ! -x "/usr/lib/v/$V_VERSION/bin/v" ]]; then
install_v_version "$V_VERSION"
fi
# Run the project with the specified version of V
/usr/lib/v/$V_VERSION/bin/v "$@"
I am still against adding things like this until 1.0 or after.
At present, people are still better off always using the latest version of V, even if there was a change that means they need to update their code - often those changes are necessary to avoid more serious issues.
Describe the feature
Something like
sdkman
ornvm
to avoid compatibility problems with packages and in production softwares. maybe:v.mod
.vvmrc
or
Use Case
Build to production
Proposed Solution
When running
v <project>
orv run <project>
it must the get the version in.vvmrc
(if it exists), and then run the project with that version of V. If the version is not found in.vvmrc
then it should use the latest version of V installed on the system or the in use version of V. If the version in.vvmrc
is not installed on the system, it should install that version and then run the project with that version of V, Maybe installing it at/usr/lib/v/<version>/bin/v
and/or/usr/local/bin/v<version>
.Other Information
It is need verify if will need have some change how vlib/v/util/version/version.v, cmd/tools/vup.v and
@VCURRENTHASH
works.Acknowledgements
Version used
V 0.4.6 209063f
Environment details (OS name and version, etc.)
all