Skip to content

Commit

Permalink
Merge pull request #321 from lsst/tickets/DM-42180
Browse files Browse the repository at this point in the history
DM-42180: Fix getopts usage to allow zsh
  • Loading branch information
timj authored Dec 14, 2023
2 parents be827c7 + 4af6b3b commit e3baa7d
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 30 deletions.
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
args:
- "--unsafe"
- id: end-of-file-fixer
- id: trailing-whitespace
11 changes: 4 additions & 7 deletions bin/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,25 @@ parse_args() {

# We are intentionally not using gnu `getopt` due to portability concerns.
# Sadly, this means no long options without a massive amount of boilerplate.
while getopts "hrvx" opt; do
while getopts "hr:v:x:" opt; do
case "$opt" in
h)
usage
;;
v)
shift;
[[ -n $TAG ]] && usage "Cannot specify both -v and -x"
[[ -n $ENVREF ]] && usage "Cannot specify both -v and -r"
ENV_VERSION=$1
ENV_VERSION=${OPTARG}
;;
x)
shift;
[[ -n $ENV_VERSION ]] && usage "Cannot specify both -x and -v"
[[ -n $ENVREF ]] && usage "Cannot specify both -x and -r"
TAG=$1
TAG=${OPTARG}
;;
r)
shift;
[[ -n $TAG ]] && usage "Cannot specify both -r and -x"
[[ -n $ENV_VERSION ]] && usage "Cannot specify both -r and -v"
ENVREF=$1
ENVREF=${OPTARG}
;;
*)
usage "Unknown option: ${opt}"
Expand Down
12 changes: 5 additions & 7 deletions bin/envconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,20 @@ usage() {
)

finish=true

}

parse_args() {
local OPTIND
local opt

while getopts "bnih" opt; do
while getopts "b:n:ih" opt; do
case "$opt" in
b)
shift;
BUILD_ID=$1
BUILD_ID=${OPTARG}
;;
n)
shift;
ENV_NAME=$1
ENV_NAME=${OPTARG}
;;
i)
INTERACTIVE=true
Expand Down Expand Up @@ -114,7 +112,7 @@ if $INTERACTIVE ; then
LSST_CONDA_ENV_NAME="${envs[${eid}]}"
fi
elif [[ $ENV_NAME != "" ]]; then
echo "Setting $ENV_NAME environment..."
echo "Setting $ENV_NAME environment..."
LSST_CONDA_ENV_NAME=${ENV_NAME}
elif [[ $BUILD_ID != "" ]]; then
echo "Looking for the environment used in build ${BUILD_ID}..."
Expand Down
6 changes: 3 additions & 3 deletions bin/envconfig.csh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set BUILD_ID = ""

if ( ! "$?1" ) then
if ( "$1" == "-h" ) then
echo "Usage: source bin/envconfig.csh [-i] [-n] [-b] [-h]"
echo "Usage: source bin/envconfig.csh [-i] [-n] [-b] [-h]"
echo
echo " -i interactive, choose from a list of available environments"
echo " -n NAME activate the environment NAME"
Expand Down Expand Up @@ -94,7 +94,7 @@ if ( "$1" == "-i" ) then
set env_list= ( `conda env list | grep -v "^#" | grep -v "^ " | grep -v "^base" | awk '{print $1}'` )
echo
@ i = 0
@ nenvs = $#env_list
@ nenvs = $#env_list
echo "Found" $nenvs "environment(s):"
while ( $i < $nenvs )
@ i++
Expand All @@ -118,7 +118,7 @@ if ( "$1" == "-i" ) then
exit
endif
echo "Activating environment" $env_list[$eid]
set LSST_CONDA_ENV_NAME = ( $env_list[$eid] )
set LSST_CONDA_ENV_NAME = ( $env_list[$eid] )
endif

if ( ! $?LSST_SPLENV_REF) then
Expand Down
8 changes: 4 additions & 4 deletions bin/mass-tag
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
if [[ -z $1 ]]; then
(cat <<-EOF
Usage: $0 [-d] <tag>
-d : instead of setting it, delete the tag
WARNING: THIS WILL APPLY <tag> TO ALL LSST/DMS REPOSITORIES IN ./build
AND IMMEDIATELY PUSH THEM TO THE UPSTREAM GIT SERVER.
EXERCISE EXTREME CAUTION.
EOF
) >&2
exit 1
Expand Down
10 changes: 5 additions & 5 deletions bin/rebuild
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ usage() {
fi

# note that heredocs are prefixed with tab chars
fail "$(cat <<-EOF
fail "$(cat <<-EOF
Usage: $0 [-p] [-n] [-u] [-r <ref> [-r <ref2> [...]]] [-t <eupstag>] product1 [product2 [...]]
Build one or more products.
Build one or more products.
It requires that the environment has previously been setup using envconfig.
Specific options:
Expand All @@ -60,11 +60,11 @@ save_build_env() {
# Saving environment information
# Using conda-forge/rubin-env to create the environment,
# there is no exact reference to refer to.
#
#
# The information saved here has the following scopes:
# - save the environment name corresponding to the buildID (locally)
# to allow a new build based on the same environment.
# - persist the exact environment resolved for this build, since
# - persist the exact environment resolved for this build, since
# this is not static, but will change with time.
# This information is also placed in EUPS_PKGROOT by publish.

Expand Down Expand Up @@ -157,7 +157,7 @@ fi
(
cd "$VERSIONDB"
current_branch="$(git branch --show-current)"
if [[ $current_branch != main ]]; then
if [[ $current_branch != main ]]; then
git branch -m "$current_branch" main
git fetch origin
git branch -u origin/main main
Expand Down
4 changes: 2 additions & 2 deletions bin/set_prereleased_env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Deploy a new environment using a given rubin-env fork and branch
#
# It is meant to be executed in after bin/deploy.
# The environment has to be enabled using envconfig -n
# The environment has to be enabled using envconfig -n
#

SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)
Expand Down Expand Up @@ -54,7 +54,7 @@ parse_args() {
done
shift $((OPTIND-1))

if [ "$#" -ne 2 ]; then
if [ "$#" -ne 2 ]; then
usage "Illegal number of parameters"
fi

Expand Down
1 change: 0 additions & 1 deletion bin/setup.csh
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ endif
echo "Sourcing bin/envconfig.csh instead"
echo
source "$LSSTSW/bin/envconfig.csh"

1 change: 0 additions & 1 deletion bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ fi
echo "Sourcing bin/envconfig instead"
# shellcheck source=./bin/envconfig
source "${LSSTSW}/bin/envconfig" 0

0 comments on commit e3baa7d

Please sign in to comment.