Skip to content

Commit

Permalink
Improve index.sh help outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
D-Pow committed May 19, 2024
1 parent a9f3964 commit 10be51d
Showing 1 changed file with 46 additions and 14 deletions.
60 changes: 46 additions & 14 deletions index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,6 @@ build() (
;;
h)
echo "$USAGE" >&2
(
cd "${serverDir}"
# Same as `./gradlew printCommands` except with colored output
./gradlew -q tasks --all
)

return 1
;;
Expand Down Expand Up @@ -220,18 +215,30 @@ hashJar() (


dockerBuild() (
declare USAGE="${FUNCNAME[0]} [OPTIONS...]
Builds a Docker image of the app.
Options:
-b | Builds a fresh .jar file (ignoring existing .jar files from manual builds).
-v | Verbose output.
-h | Print this help message and exit.
"
declare _dockerBuildFreshJar=
declare _dockerBuildVerbose=
declare OPTIND=1

while getopts ":bv" opt; do
while getopts ":bvh" opt; do
case "$opt" in
b)
_dockerBuildFreshJar=true
;;
v)
_dockerBuildVerbose=true
;;
h)
echo -e "$USAGE"
return 1
;;
*)
# Forward options to `docker` command
break
Expand Down Expand Up @@ -985,6 +992,7 @@ main() {
Options:
-i | Install build-script dependencies if not present (e.g. \`nvm\`).
-v | Verbose help output for both client and server.
-h | Print this help message and exit.
Commands:
Expand All @@ -997,18 +1005,17 @@ $(
)
"

declare _printHelp=
declare _verboseHelpOutput=
declare OPTIND=1

while getopts ":ih" opt; do
while getopts ":ivh" opt; do
case "$opt" in
v)
_verboseHelpOutput=true
;;
h)
if (( $# == 1 )); then
# User ran `thisFile -h` rather than `thisFile command -h`
# so print `main()` help message.
# The latter format's command should handle flags itself.
echo -e "$USAGE"
return 1
fi
_printHelp=true
;;
i)
"${rootDir}/nvm-install.sh"
Expand All @@ -1021,6 +1028,31 @@ $(

shift $(( OPTIND - 1 ))

if [[ -n "$_printHelp" ]] || (( $# == 1 )); then
# `(( $# == 1 ))` means user ran `thisFile -h` rather than `thisFile command -h`.
# The latter format's command should handle flags itself.
echo -e "$USAGE"

if [[ -n "$_verboseHelpOutput" ]]; then
declare clientDirRelative="$(realpath --relative-to="$rootDir" "$clientDir")"
echo -e "\n\n$clientDirRelative npm tasks:\n"
(
cd "${clientDir}"
npm run
)

declare serverDirRelative="$(realpath --relative-to="$rootDir" "$serverDir")"
echo -e "\n\n$serverDirRelative Gradle tasks:"
(
cd "${serverDir}"
# Same as `./gradlew printCommands` except with colored output
./gradlew -q tasks --all
)
fi

return 1
fi

declare cmd="$1" # First arg = command to run. Last arg = `${@:$#}``
declare cmdArgs=("${@:2}")

Expand Down

0 comments on commit 10be51d

Please sign in to comment.