This page contains snippets of code which uses arch commands or API to perform small utilitarian tasks. Of course, feel free to post things more substantial than snippets.
Contents
Generate Tree Version String
The purpose of this snippet is to generate a version string using the current revision of a project tree.
getProjectVersion() {
local pt=$1
cd ${pt}
local TREE_VERSION_STRING=`tla tree-version`
local TREE_BRANCH=`tla parse-package-name -b ${TREE_VERSION_STRING}`
local TREE_VERSION=`tla parse-package-name -v ${TREE_VERSION_STRING}`
local TREE_REVISION=`tla logs -r | head -n 1`
local VERSION_STRING="`basename ${pt}`-${TREE_BRANCH}-${TREE_VERSION}"
local REVISION_TAG=`echo ${TREE_REVISION} | gawk -F\- '{print $1}'`
local REVISION_NUM=`echo ${TREE_REVISION} | gawk -F\- '{print $2}'`
case "${REVISION_TAG}" in
patch) VERSION_STRING="${VERSION_STRING}pre${REVISION_NUM}" ;;
version) ;;
versionfix) VERSION_STRING="${VERSION_STRING}.${REVISION_NUM}" ;;
esac
echo ${VERSION_STRING}
# OR if you would rather return it in a variable you could pass the variable
# name as $2 and uncomment the following
# eval $2=\$VERSION_STRING
}
This shell function will produce a string such as projname-branch-1.0pre7 given a path to a project tree /some/path/projname which has a branch of branch and a version 1.0 and it's latest revision in the project tree is patch-7. Of course this could be easily modified to produce a different output, This suited my needs.
