From 50c9b6d692d8ba6ae35520705856aeae632ed3e3 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Fri, 17 Sep 2021 15:32:56 +0200 Subject: [PATCH 1/4] modulecmd: fix output of module avail - for directories outside the hierarchy the header did not include the directory name. --- Pmodules/modulecmd.bash.in | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index fc51ad6..3382b36 100644 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -1042,8 +1042,12 @@ subcommand_avail() { local string for string in "${pattern[@]}"; do for dir in "${modulepath[@]}"; do - local group="${dir/${PMODULES_ROOT}\/}" - group="${group%%/*}" + if [[ ${dir} =~ ${PMODULES_ROOT} ]]; then + local group="${dir/${PMODULES_ROOT}\/}" + group="${group%%/*}" + else + local group="${dir}" + fi if (( ${#opt_groups[@]} > 0 )) && [[ ! -v opt_groups[${group}] ]]; then continue fi From 6d6609126f7cdc8b3c19e4e6365cd0319251a2cd Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Thu, 28 Oct 2021 18:20:58 +0200 Subject: [PATCH 2/4] fixes in module search sub-command - error fixed in printing the modulefile - sanity checks added if --src is specified (cherry picked from commit c22422aca93d11d0addd9beae31995305d56f6ac) --- Pmodules/modulecmd.bash.in | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index 3382b36..e009069 100644 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -1771,7 +1771,7 @@ subcommand_search() { print_modulefiles() { fmt='' func_print_header='print_header_none' - func_print_line='print_header_none' + func_print_line='print_line_modulefile' } print_header_none() { @@ -1779,16 +1779,7 @@ subcommand_search() { } print_line_modulefile() { - local line=( "$@" ) - # group first - local out="${line[2]}/" - # add directory of modulefiles - out+="${PMODULES_MODULEFILES_DIR}/" - for d in "${line[@]:3}"; do - out+="$d/" - done - out+="${line[0]}" - std::info "${out}" + std::info "$4" } print_line_csv() { @@ -1952,10 +1943,26 @@ subcommand_search() { -a | --all-releases ) opt_use_rel_stages+="${ReleaseStages}" ;; - --src ) - # :FIXME: do we have to add some sanity checks here? - src_prefix=$2 - shift + --src | --src=*) + if [[ "$1" == --src ]]; then + local src_prefix="$2" + shift + else + local src_prefix="${1/--src=}" + fi + if [[ ! -e "${src_prefix}" ]]; then + std::die 1 "%s %s: %s -- %s" \ + "${CMD}" 'search' \ + "illegal value for --src option" \ + "${src_prefix} does not exist" + fi + if [[ ! -d "${src_prefix}" ]]; then + std::die 1 "%s %s: %s -- %s" \ + "${CMD}" 'search' \ + "illegal value for --src option" \ + "${src_prefix} is not a directory" + fi + src_prefix=$(std::get_abspath "${src_prefix}") ;; -v | --verbose ) opt_print_verbose='yes' From 3d326a527aee094cbf069d5cc09d0873a85ab831 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Fri, 29 Oct 2021 12:05:41 +0200 Subject: [PATCH 3/4] modulecmd: sort output of sub-command avail numerically --- Pmodules/modulecmd.bash.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index e009069..02d22ab 100644 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -972,6 +972,8 @@ subcommand_avail() { (( n > max_length )) && (( max_length=n )) available_modules+=("${mod}") done + IFS=$'\n' available_modules=($(sort --version-sort <<<"${available_modules[*]}")) + unset IFS local -i span=$(( max_length / 16 + 1 )) # compute column size local -i colsize=$(( span * 16 )) # as multiple of 16 local -i column=$cols # force a line-break From ef5dd9f761e716ea27b221ef3b55403fcf35ec23 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Fri, 29 Oct 2021 13:54:22 +0200 Subject: [PATCH 4/4] modulecmd: fixes in option and argument parsing --- Pmodules/modulecmd.bash.in | 62 ++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index 02d22ab..1644675 100644 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -258,7 +258,9 @@ subcommand_generic0() { print_help "${subcommand}" ;; -- ) - : + shift 1 + args+=( "$@" ) + break ;; * ) args+=( "$1" ) @@ -284,7 +286,9 @@ subcommand_generic1() { print_help "${subcommand}" ;; -- ) - : + shift 1 + args+=( "$@" ) + break ;; * ) args+=( "$1" ) @@ -314,7 +318,9 @@ subcommand_generic1plus() { print_help "${subcommand}" ;; -- ) - : + shift 1 + args+=( "$@" ) + break ;; * ) args+=( "$1" ) @@ -477,6 +483,9 @@ subcommand_load() { verbosity_lvl='warn' ;; -- ) + shift 1 + args+=( "$@" ) + break ;; * ) args+=( $1 ) @@ -678,6 +687,9 @@ subcommand_unload() { print_help "${subcommand}" ;; -- ) + shift 1 + args+=( "$@" ) + break ;; * ) args+=( "$1" ) @@ -744,6 +756,9 @@ subcommand_swap() { print_help "${subcommand}" ;; -- ) + shift 1 + args+=( "$@" ) + break ;; * ) args+=( "$1" ) @@ -798,6 +813,9 @@ subcommand_show() { print_help "${subcommand}" ;; -- ) + shift 1 + args+=( "$@" ) + break ;; * ) args+=( "$1" ) @@ -1027,7 +1045,12 @@ subcommand_avail() { fi opt_groups[${val}]=1 ;; - -- | '' ) + '' ) + ;; + -- ) + shift 1 + pattern+=( "$@" ) + break ;; * ) pattern+=( "$1" ) @@ -1219,6 +1242,9 @@ subcommand_use() { add2path_func='std::prepend_path' ;; -- ) + shift 1 + args+=( "$@" ) + break ;; * ) args+=( "$1" ) @@ -1324,6 +1350,9 @@ subcommand_unuse() { print_help "${subcommand}" ;; -- ) + shift 1 + args+=( "$@" ) + break ;; * ) args+=( "$1" ) @@ -1482,6 +1511,9 @@ subcommand_purge() { print_help "${subcommand}" ;; -- ) + shift 1 + args+=( "$@" ) + break ;; * ) args+=( "$1" ) @@ -1577,6 +1609,9 @@ subcommand_list() { opts+=( '-t' ) ;; -- ) + shift 1 + args+=( "$@" ) + break ;; * ) args+=( "$1" ) @@ -1615,7 +1650,9 @@ subcommand_clear() { print_help "${subcommand}" ;; -- ) - : + shift 1 + args+=( "$@" ) + break ;; * ) args+=( "$1" ) @@ -1973,6 +2010,9 @@ subcommand_search() { opt_wrap='yes' ;; -- ) + shift 1 + modules+=( "$@" ) + break ;; * ) modules+=( "$1" ) @@ -2054,7 +2094,9 @@ subcommand_help() { print_help 'version' ;; -- ) - : + shift 1 + args+=( "$@" ) + break ;; * ) args+=( "$1" ) @@ -2209,7 +2251,9 @@ subcommand_initswitch() { print_help "${subcommand}" ;; -- ) - : + shift 1 + args+=( "$@" ) + break ;; * ) args+=( "$1" ) @@ -2288,7 +2332,7 @@ while (( $# > 0 )); do --debug ) set -x ;; - '' | -- ) + '' ) ;; -* ) opts+=( "$1" ) @@ -2379,7 +2423,7 @@ case ${subcommand} in esac declare options -options=$( "${getopt}" ${Options[${subcommand}]} -- -- "${opts[@]}" "$@" ) \ +options=$( "${getopt}" ${Options[${subcommand}]} -- "${opts[@]}" "$@" ) \ || print_help "${subcommand}" eval set -- ${options} subcommand_${Subcommands[$subcommand]} "$@"