Skip to content

Commit

Permalink
devonfw#826: List and set versions
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahffm committed Sep 27, 2022
1 parent d250ffa commit 0e5ace1
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion scripts/src/main/resources/scripts/functions
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,39 @@ function doRequireWsl() {
doFail "${error}\nTo fix this follow these instructions:\nhttps://docs.microsoft.com/en-us/windows/wsl/install-win10"
}

# $1: software
# $2: selected version
function doSetSoftwareVersion() {
local software="${1}"
local version="${2}"
if [ ! -z "${version}" ]
then
if [ "${version}" = "latest" ]
then
version="$(head -n 1 ${DEVON_IDE_HOME}/mirrors/${software}/available-versions)"
fi
grep -v "${software^^}_VERSION" ${DEVON_IDE_HOME}/settings/devon.properties > ${DEVON_IDE_HOME}/settings/devon.properties.tmp
mv ${DEVON_IDE_HOME}/settings/devon.properties.tmp ${DEVON_IDE_HOME}/settings/devon.properties
echo "${software^^}_VERSION=\"${version}\"" >> ${DEVON_IDE_HOME}/settings/devon.properties
else
doError "You have to specify the version you want to set."
fi
}

# $1: software
function doListSoftwareVersions() {
local versions_path="${DEVON_IDE_HOME}/mirrors/${1}/available-versions"
if [ "$(wc -l ${versions_path} | awk '{print $1}')" -lt 20 ]
then
pr -4 -t -s "${versions_path}"
else
head -n 20 "${versions_path}" | pr -4 -t -s
doEcho "Only the 20 latest versions are displayed."
doAskToContinue "Do you want to see all versions?"
less "${versions_path}"
fi
}

# $1: single CLI arg
# returns 0 if a standard option was detected and handled, 255 otherwise (regular argument to be handeled by CLI parser)
function doParseOption() {
Expand Down Expand Up @@ -1578,6 +1611,16 @@ function doParseOption() {
then
quiet="${1}"
return
elif [ "${1}" = "version" ]
then
if [ "${2}" = "list" ]
then
doListSoftwareVersions "$(basename ${0})"
elif [ "${2}" = "set" ]
then
doSetSoftwareVersion "$(basename ${0})" "${3}"
fi
exit
fi
return 255
}
Expand All @@ -1587,7 +1630,7 @@ batch=""
force=""
quiet=""
debug=""
while [ -n "${1}" ] && doParseOption "${1}"
while [ -n "${1}" ] && doParseOption "${@}"
do
shift
done

0 comments on commit 0e5ace1

Please sign in to comment.