install.sh: Implement flag parsing

This commit is contained in:
Anmol Sethi 2022-11-13 23:17:46 -08:00
parent be6f186ee0
commit ca336e8fcf
2 changed files with 75 additions and 4 deletions

View file

@ -13,7 +13,7 @@ help() {
fi fi
cat <<EOF cat <<EOF
usage: $arg0 [--dryrun] [--version vX.X.X] [--edge] [--method detect] [--prefix ~/.local] usage: $arg0 [--dry-run] [--version vX.X.X] [--edge] [--method detect] [--prefix ~/.local]
[--tala] [--tala-version vX.X.X] [--force] [--uninstall] [--tala] [--tala-version vX.X.X] [--force] [--uninstall]
install.sh automates the installation of D2 onto your system. It currently only supports install.sh automates the installation of D2 onto your system. It currently only supports
@ -22,15 +22,20 @@ source, build a release and install from it.
Flags: Flags:
--dryrun --dry-run
Pass to have install.sh show the install method and flags that will be used to install Pass to have install.sh show the install method and flags that will be used to install
without executing them. Very useful to understand what changes it will make to your system. without executing them. Very useful to understand what changes it will make to your system.
--version vX.X.X --version vX.X.X
Pass to have install.sh install the given version instead of the latest version. Pass to have install.sh install the given version instead of the latest version.
note: currently unimplemented.
--edge --edge
Pass to build and install D2 from source. Pass to build and install D2 from source. This will still use --method if set to detect
to install the release archive for your OS, whether it's apt, yum, brew or standalone
if an unsupported package manager is used. To install from source like a dev would,
use go install oss.terrastruct.com/d2
note: currently unimplemented.
--method [detect | standalone] --method [detect | standalone]
Pass to control the method by which to install. Right now we only support standalone Pass to control the method by which to install. Right now we only support standalone
@ -55,6 +60,7 @@ Flags:
--tala-version vX.X.X --tala-version vX.X.X
Install the passed version of tala instead of latest. Install the passed version of tala instead of latest.
note: currently unimplemented.
--force: --force:
Force installation over the existing version even if they match. It will attempt a clean Force installation over the existing version even if they match. It will attempt a clean
@ -74,3 +80,68 @@ You can rerun install.sh to update your version of D2. install.sh will avoid rei
if the installed version is the latest unless --force is passed. if the installed version is the latest unless --force is passed.
EOF EOF
} }
main() {
while :; do
flag_parse "$@"
case "$FLAG" in
h|help)
help
return 0
;;
dry-run)
flag_noarg && shift "$FLAGSHIFT"
DRY_RUN=1
;;
version)
flag_nonemptyarg && shift "$FLAGSHIFT"
VERSION=$FLAGARG
echoerr "$FLAGRAW is currently unimplemented"
exit 1
;;
tala-version)
flag_nonemptyarg && shift "$FLAGSHIFT"
TALA_VERSION=$FLAGARG
echoerr "$FLAGRAW is currently unimplemented"
exit 1
;;
edge)
flag_noarg && shift "$FLAGSHIFT"
EDGE=1
echoerr "$FLAGRAW is currently unimplemented"
exit 1
;;
method)
flag_nonemptyarg && shift "$FLAGSHIFT"
METHOD=$FLAGARG
echoerr "$FLAGRAW is currently unimplemented"
exit 1
;;
prefix)
flag_nonemptyarg && shift "$FLAGSHIFT"
export PREFIX=$FLAGARG
;;
force)
flag_noarg && shift "$FLAGSHIFT"
FORCE=1
;;
uninstall)
flag_noarg && shift "$FLAGSHIFT"
UNINSTALL=1
;;
'')
shift "$FLAGSHIFT"
break
;;
*)
flag_errusage "unrecognized flag $FLAGRAW"
;;
esac
done
if [ $# -gt 0 ]; then
flag_errusage "no arguments are accepted"
fi
}
main "$@"

2
ci/sub

@ -1 +1 @@
Subproject commit 4f1fb95079b0ef0057db7ea65db5a1ca9f053dda Subproject commit 81e033b7702131e917a16396b44c20512d29029b