From 0fe304880427b2c1a6b3900e071fbf7ee1937ac4 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Thu, 16 May 2019 16:44:23 +0200 Subject: [PATCH] re-implementation of sub-command 'swap' - sub-command 'swap' is now implemented via unload/load - tmpfile variable in subcommand_load() cannot be read-only any more --- Pmodules/modulecmd.bash.in | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index f6f49c9..7d3800c 100755 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -824,11 +824,12 @@ subcommand_load() { if [[ ${current_modulefile} =~ ${PMODULES_ROOT} ]]; then # modulefile is in our hierarchy # ${prefix} was set in is_available()! + test -r "${prefix}/.info" && cat "$_" 1>&2 test -r "${prefix}/.dependencies" && load_dependencies "$_" fi - local -r tmpfile=$( "${mktemp}" /tmp/Pmodules.XXXXXX ) \ + local tmpfile=$( "${mktemp}" /tmp/Pmodules.XXXXXX ) \ || std::die 1 "Oops: unable to create tmp file!\n" - local output=$("${modulecmd}" "${shell}" ${opts} load "${current_modulefile}" 2> "${tmpfile}") + local output=$("${modulecmd}" "${shell}" ${opts} 'load' "${current_modulefile}" 2> "${tmpfile}") echo "${output}" eval "${output}" local error=$( < "${tmpfile}") @@ -884,7 +885,7 @@ subcommand_unload() { fi for arg in "${args[@]}"; do - local output=$("${modulecmd}" "${g_shell}" "${subcommand}" "${arg}") + local output=$("${modulecmd}" "${g_shell}" 'unload' "${arg}") echo "${output}" eval "${output}" done @@ -894,7 +895,36 @@ subcommand_unload() { # swap [] # subcommand_swap() { - subcommand_generic1or2 swap "$@" + local opts=() + pmodules::get_options opts -- '' "$@" || subcommand_help_${subcommand} + eval set -- "${opts[@]}" + local args=() + while (( $# > 0 )); do + case $1 in + -- ) + ;; + * ) + args+=( "$1" ) + ;; + esac + shift + done + if (( ${#args[@]} == 0 )); then + std::die 3 "%s %s: missing argument\n" \ + "${CMD}" 'unload' + elif (( ${#args[@]} > 2 )); then + std::die 3 "%s %s: too many arguments\n" \ + "${CMD}" 'unload' + fi + if (( ${#args[@]} == 1 )); then + module_to_load=${args[0]} + module_to_unload=${module_to_load%/*} + else + module_to_unload=${args[0]} + module_to_load=${args[1]} + fi + subcommand_unload "${module_to_unload}" + subcommand_load "${module_to_load}" } #