Last active
January 31, 2023 11:16
-
-
Save svandragt/4d86830edd2024823b1b0438aff42f8e to your computer and use it in GitHub Desktop.
./composer-require-git myorg/mypackage:dev-main
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#{{{ Bash settings | |
# abort on nonzero exitstatus | |
set -o errexit | |
# abort on unbound variable | |
set -o nounset | |
# don't hide errors within pipes | |
set -o pipefail | |
#}}} | |
#{{{ Variables | |
IFS=$'\t\n' # Split on newlines and tabs (but not on spaces) | |
SCRIPT_NAME=$(basename "${0}") | |
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) | |
readonly SCRIPT_NAME SCRIPT_DIR | |
#}}} | |
if (( $# != 1 )); then | |
>&2 echo "Illegal number of parameters." | |
>&2 echo "Syntax: $SCRIPT_NAME org/package:version_constraint" | |
fi | |
IN=$1 | |
VERSION_CONSTRAINT=$(echo $IN| cut -d ":" -f 2) | |
ORG_PACKAGE=$(echo $IN| cut -d ":" -f 1) | |
PACKAGE_NAME=$(echo $ORG_PACKAGE| cut -d "/" -f 2) | |
echo "ORG_PACKAGE: $ORG_PACKAGE" | |
echo "PACKAGE_NAME: $PACKAGE_NAME" | |
echo "VERSION_CONSTRAINT: $VERSION_CONSTRAINT" | |
read -p "Add this git repository? (y/n)? " choice | |
case "$choice" in | |
y|Y ) | |
set -x | |
composer config repositories.$PACKAGE_NAME vcs [email protected]:$ORG_PACKAGE.git | |
composer require $ORG_PACKAGE:$VERSION_CONSTRAINT --no-update | |
composer update $ORG_PACKAGE --prefer-source | |
set +x | |
;; | |
n|N ) | |
exit 0 | |
;; | |
* ) | |
echo "invalid" | |
exit 1 | |
;; | |
esac | |
Author
svandragt
commented
Jan 27, 2023
Updated the script to prefer source.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment