Skip to content

Instantly share code, notes, and snippets.

@nmccready
Last active April 20, 2022 01:53
Show Gist options
  • Save nmccready/26bd956b417aade97808453d7b95c6c7 to your computer and use it in GitHub Desktop.
Save nmccready/26bd956b417aade97808453d7b95c6c7 to your computer and use it in GitHub Desktop.
parse args and forward
# !/usr/bin/env bash
ROOT_DIR=$(pwd)
helpMenu() {
echo '
-i|--install) install all dependencies
-in|--install-node) install node dependencies
-if|--install-flutter) install flutter dependencies
-h|--help) this menu
'
}
usage_error () { echo >&2 "$(basename $0): $1"; exit 2; }
install_node() {
for i in $(find ./packages -name "package.json" | grep -v node_modules); do
local loc=$(echo "$i" | sed 's/\/package.json//g')
cd "$loc"
echo
echo "install $loc"
npm install
echo "done install $loc"
cd "$ROOT_DIR"
done
echo "== node dependencies done =="
}
# Because melos is not ready (hangs and swallows output)
# see https://github.com/invertase/melos/issues/135
install_flutter(){
for i in $(find ./packages -name "pubspec.yaml"); do
local loc=$(echo "$i" | sed 's/\/pubspec.yaml//g')
cd "$loc"
flutter pub get
cd "$ROOT_DIR"
done
echo "== flutter dependencies done =="
}
install() {
install_flutter
install_node
}
while [[ "$#" > 0 ]]; do case $1 in
-i|--install) install;;
-in|--install-node) install_node;;
-if|--install-flutter) install_flutter;;
-h|--help) helpMenu;;
# -r|--repository-name) shift; DOCKER_REPO=$1;;
-*) usage_error "unknown option: '$1'";;
*) usage_error "this should NEVER happen ($1)";;
esac; shift; done
while [[ "$#" > 0 ]]; do case $1 in
-j|--package-json) shift; PACKAGE_JSON_LOC=$1;;
-r|--repository-name) shift; DOCKER_REPO=$1;;
*) args[${#args[@]}]=$1;;
esac; shift; done
someFunction ${args[@]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment