This repository has been archived by the owner on Jun 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor config command to prevent double-argv parsing (#665)
- Loading branch information
Showing
7 changed files
with
171 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,49 @@ | ||
#!/bin/sh | ||
|
||
# shellcheck disable=SC2068 | ||
"$RELEASE_ROOT_DIR/bin/ewallet" command Elixir.EWallet.ReleaseTasks config $@ | ||
print_usage() { | ||
printf "Usage: bin/ewallet config [OPTS] KEY VALUE\\n" | ||
printf "\\n" | ||
printf "Update the eWallet configuration in the database.\\n" | ||
printf "\\n" | ||
printf "This command uses POSIX sh shell escaping to handle argument\\n" | ||
printf "splitting, this means you MUST escape quotes if it was intended\\n" | ||
printf "as part of a configuration value. For example:\\n" | ||
printf "\\n" | ||
printf " bin/ewallet config example \"{\\\"key\\\": \\\"value\\\"}\"\\n" | ||
printf "\\n" | ||
printf "Alternatively, use a single quote:\\n" | ||
printf "\\n" | ||
printf " bin/ewallet config example '{\"key\": \"value\"}'\\n" | ||
printf "\\n" | ||
printf "OPTS:\\n" | ||
printf "\\n" | ||
printf " -h Prints this help.\\n" | ||
printf "\\n" | ||
} | ||
|
||
ARGS=$(getopt -s sh h "$@" 2>/dev/null) | ||
|
||
# shellcheck disable=SC2181 | ||
if [ $? != 0 ]; then | ||
print_usage | ||
exit 1 | ||
fi | ||
|
||
eval set -- "$ARGS" | ||
|
||
while true; do | ||
case "$1" in | ||
-h ) print_usage; exit 2;; | ||
-- ) shift; break;; | ||
* ) break;; | ||
esac | ||
done | ||
|
||
# We don't want to deal with argument parsing again in Elixir. No, just no. | ||
# Let's sidestep all issues by passing the already-parsed value as Base64 | ||
# and let the release task decode it. | ||
|
||
KEY="$(printf "%s" "$1" | base64)"; shift | ||
VALUE="$(printf "%s" "$1" | base64)"; shift | ||
|
||
exec "$RELEASE_ROOT_DIR/bin/ewallet" command Elixir.EWallet.ReleaseTasks config_base64 "$KEY" "$VALUE" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,31 @@ | ||
#!/bin/sh | ||
|
||
"$RELEASE_ROOT_DIR/bin/ewallet" command Elixir.EWallet.ReleaseTasks initdb | ||
print_usage() { | ||
printf "Usage: bin/ewallet initdb [OPTS]\\n" | ||
printf "\\n" | ||
printf "Create and upgrade the database.\\n" | ||
printf "\\n" | ||
printf "OPTS:\\n" | ||
printf "\\n" | ||
printf " -h Prints this help.\\n" | ||
printf "\\n" | ||
} | ||
|
||
ARGS=$(getopt -s sh h "$@" 2>/dev/null) | ||
|
||
# shellcheck disable=SC2181 | ||
if [ $? != 0 ]; then | ||
print_usage | ||
exit 1 | ||
fi | ||
|
||
eval set -- "$ARGS" | ||
|
||
while true; do | ||
case "$1" in | ||
-h ) print_usage; exit 2;; | ||
* ) break;; | ||
esac | ||
done | ||
|
||
exec "$RELEASE_ROOT_DIR/bin/ewallet" command Elixir.EWallet.ReleaseTasks initdb |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,40 @@ | ||
#!/bin/sh | ||
|
||
seed_spec=seed | ||
print_usage() { | ||
printf "Usage: bin/ewallet seed [OPTS]\\n" | ||
printf "\\n" | ||
printf "Seeds the database with initial data for production, testing\\n" | ||
printf "and evaluation purpose. This command does not attempt to\\n" | ||
printf "detect whether the database has already been seeded or not and\\n" | ||
printf "is expected to be run only once after running initdb.\\n" | ||
printf "\\n" | ||
printf "OPTS:\\n" | ||
printf "\\n" | ||
printf " -h Prints this help.\\n" | ||
printf " -e --e2e Seeds the end-to-end testing data.\\n" | ||
printf " -s --sample Seeds the sample data.\\n" | ||
printf "\\n" | ||
} | ||
|
||
while [ "$#" -gt 0 ]; do case $1 in | ||
-e|--e2e) seed_spec=seed_e2e;; | ||
*) echo "$0: illegal option -- $1"; exit 1;; | ||
esac; shift; done | ||
ARGS=$(getopt -s sh -l e2e -l sample hes "$@" 2>/dev/null) | ||
|
||
"$RELEASE_ROOT_DIR/bin/ewallet" command Elixir.EWallet.ReleaseTasks "${seed_spec}" | ||
# shellcheck disable=SC2181 | ||
if [ $? != 0 ]; then | ||
print_usage | ||
exit 1 | ||
fi | ||
|
||
eval set -- "$ARGS" | ||
|
||
SEED_SPEC=seed | ||
|
||
while true; do | ||
case "$1" in | ||
-e | --e2e ) SEED_SPEC=seed_e2e; shift;; | ||
-s | --sample ) SEED_SPEC=seed_sample; shift;; | ||
-h ) print_usage; exit 2;; | ||
* ) break;; | ||
esac | ||
done | ||
|
||
exec "$RELEASE_ROOT_DIR/bin/ewallet" command Elixir.EWallet.ReleaseTasks "$SEED_SPEC" |
This file contains 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
This file contains 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