-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Revamp Elixir CLI #8595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revamp Elixir CLI #8595
Changes from all commits
24794e2
bc16959
de75ead
c43cc9f
7922e56
0a71ac0
ffcda46
aba9c93
933d6fb
d1ec996
a7d4cbd
a72b8c7
09871cd
f6b5021
abb9026
5469e73
55d191f
d26e0d9
ec7c714
5ff9c0a
58c947f
3962a7e
a7c3099
a8b722c
4bed19a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,31 +1,59 @@ | ||||||
| #!/bin/sh | ||||||
| set -e | ||||||
|
|
||||||
| if [ $# -eq 0 ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then | ||||||
| echo "Usage: `basename $0` [options] [.exs file] [data] | ||||||
|
|
||||||
| -e \"COMMAND\" Evaluates the given command (*) | ||||||
| -r \"FILE\" Requires the given files/patterns (*) | ||||||
| -S SCRIPT Finds and executes the given script in PATH | ||||||
| -pr \"FILE\" Requires the given files/patterns in parallel (*) | ||||||
| -pa \"PATH\" Prepends the given path to Erlang code path (*) | ||||||
| -pz \"PATH\" Appends the given path to Erlang code path (*) | ||||||
|
|
||||||
| --app APP Starts the given app and its dependencies (*) | ||||||
| --cookie COOKIE Sets a cookie for this distributed node | ||||||
| --detached Starts the Erlang VM detached from console | ||||||
| --erl \"SWITCHES\" Switches to be passed down to Erlang (*) | ||||||
| --help, -h Prints this message and exits | ||||||
| --hidden Makes a hidden node | ||||||
| --logger-otp-reports BOOL Enables or disables OTP reporting | ||||||
| --logger-sasl-reports BOOL Enables or disables SASL reporting | ||||||
| --name NAME Makes and assigns a name to the distributed node | ||||||
| --no-halt Does not halt the Erlang VM after execution | ||||||
| --sname NAME Makes and assigns a short name to the distributed node | ||||||
| --version, -v Prints Elixir version and exits | ||||||
| --werl Uses Erlang's Windows shell GUI (Windows only) | ||||||
|
|
||||||
| ** Options marked with (*) can be given more than once | ||||||
| ** Options given after the .exs file or -- are passed down to the executed code | ||||||
| ** Options can be passed to the Erlang runtime using ELIXIR_ERL_OPTIONS or --erl" >&2 | ||||||
| echo "Usage: $(basename $0) [options] [.exs file] [data] | ||||||
|
|
||||||
| ## General options | ||||||
|
|
||||||
| -e \"COMMAND\" Evaluates the given command (*) | ||||||
| -h, --help Prints this message and exits | ||||||
| -r \"FILE\" Requires the given files/patterns (*) | ||||||
| -S SCRIPT Finds and executes the given script in \$PATH | ||||||
| -pr \"FILE\" Requires the given files/patterns in parallel (*) | ||||||
| -pa \"PATH\" Prepends the given path to Erlang code path (*) | ||||||
| -pz \"PATH\" Appends the given path to Erlang code path (*) | ||||||
| -v, --version Prints Elixir version and exits | ||||||
|
|
||||||
| --app APP Starts the given app and its dependencies (*) | ||||||
| --erl \"SWITCHES\" Switches to be passed down to Erlang (*) | ||||||
| --eval \"COMMAND\" Evaluates the given command, same as -e (*) | ||||||
| --logger-otp-reports BOOL Enables or disables OTP reporting | ||||||
| --logger-sasl-reports BOOL Enables or disables SASL reporting | ||||||
| --no-halt Does not halt the Erlang VM after execution | ||||||
| --werl Uses Erlang's Windows shell GUI (Windows only) | ||||||
|
|
||||||
| Options given after the .exs file or -- are passed down to the executed code. | ||||||
| Options can be passed to the Erlang runtime using \$ELIXIR_ERL_OPTIONS or --erl. | ||||||
|
|
||||||
| ## Distribution options | ||||||
|
|
||||||
| The following options are related to node distribution. | ||||||
|
|
||||||
| --cookie COOKIE Sets a cookie for this distributed node | ||||||
| --hidden Makes a hidden node | ||||||
| --name NAME Makes and assigns a name to the distributed node | ||||||
| --rpc-eval NODE \"COMMAND\" Evaluates the given command on the given remote node (*) | ||||||
| --sname NAME Makes and assigns a short name to the distributed node | ||||||
|
|
||||||
| ## Release options | ||||||
|
|
||||||
| The following options are generally used under releases. | ||||||
|
|
||||||
| --boot \"FILE\" Uses the given FILE.boot to start the system | ||||||
| --boot-var VAR \"VALUE\" Makes \$VAR available as VALUE to FILE.boot (*) | ||||||
| --erl-config \"FILE\" Loads configuration in FILE.config written in Erlang (*) | ||||||
| --pipe-to \"PIPEDIR\" \"LOGDIR\" Starts the Erlang VM as a named PIPEDIR and LOGDIR | ||||||
| --vm-args \"FILE\" Passes the contents in file as arguments to the VM | ||||||
|
|
||||||
| --pipe-to starts Elixir detached from console (Unix-like only). | ||||||
| It will attempt to create PIPEDIR and LOGDIR if they don't exist. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| See run_erl to learn more. To reattach, run: to_erl PIPEDIR. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| --pipe-to automatically sets \$HEART_COMMAND if none is set. | ||||||
| See the -heart mode of the Erlang VM for more information. | ||||||
|
|
||||||
| ** Options marked with (*) can be given more than once." >&2 | ||||||
| exit 1 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we just
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe it was because if Elixir is accidentally called without argument or something of sorts. So we probably need to check why we are invoking this. Let's do that in a separate occasion. |
||||||
| fi | ||||||
|
|
||||||
|
|
@@ -35,84 +63,137 @@ readlink_f () { | |||||
| if [ -h "$filename" ]; then | ||||||
| readlink_f "$(readlink "$filename")" | ||||||
| else | ||||||
| echo "`pwd -P`/$filename" | ||||||
| echo "$(pwd -P)/$filename" | ||||||
| fi | ||||||
| } | ||||||
|
|
||||||
| MODE="elixir" | ||||||
| ERL_EXEC="erl" | ||||||
| ERL="" | ||||||
| I=1 | ||||||
| LENGTH=$# | ||||||
|
|
||||||
| while [ $I -le $# ]; do | ||||||
| while [ $I -le $LENGTH ]; do | ||||||
| S=1 | ||||||
| eval "PEEK=\${$I}" | ||||||
| case "$PEEK" in | ||||||
| case "$1" in | ||||||
| +iex) | ||||||
| set -- "$@" "$1" | ||||||
| MODE="iex" | ||||||
| ;; | ||||||
| +elixirc) | ||||||
| set -- "$@" "$1" | ||||||
| MODE="elixirc" | ||||||
| ;; | ||||||
| -v|--compile|--no-halt) | ||||||
| -v|--no-halt) | ||||||
| set -- "$@" "$1" | ||||||
| ;; | ||||||
| -e|-r|-pr|-pa|-pz|--remsh|--app) | ||||||
| -e|-r|-pr|-pa|-pz|--app|--eval|--remsh) | ||||||
| S=2 | ||||||
| set -- "$@" "$1" "$2" | ||||||
| ;; | ||||||
| --rpc-eval) | ||||||
| S=3 | ||||||
| set -- "$@" "$1" "$2" "$3" | ||||||
| ;; | ||||||
| --detached|--hidden) | ||||||
| ERL="$ERL `echo $PEEK | cut -c 2-`" | ||||||
| --detached) | ||||||
| echo "warning: the --detached option is deprecated" >&2 | ||||||
| ERL="$ERL -detached" | ||||||
| ;; | ||||||
| --hidden) | ||||||
| ERL="$ERL -hidden" | ||||||
| ;; | ||||||
| --cookie) | ||||||
| I=$(expr $I + 1) | ||||||
| eval "VAL=\${$I}" | ||||||
| ERL="$ERL -setcookie "$VAL"" | ||||||
| S=2 | ||||||
| ERL="$ERL -setcookie "$2"" | ||||||
| ;; | ||||||
| --sname|--name) | ||||||
| I=$(expr $I + 1) | ||||||
| eval "VAL=\${$I}" | ||||||
| ERL="$ERL `echo $PEEK | cut -c 2-` "$VAL"" | ||||||
| S=2 | ||||||
| ERL="$ERL $(echo $1 | cut -c 2-) "$2"" | ||||||
| ;; | ||||||
| --logger-otp-reports) | ||||||
| I=$(expr $I + 1) | ||||||
| eval "VAL=\${$I}" | ||||||
| if [ "$VAL" = 'true' ] || [ "$VAL" = 'false' ]; then | ||||||
| ERL="$ERL -logger handle_otp_reports "$VAL"" | ||||||
| S=2 | ||||||
| if [ "$2" = 'true' ] || [ "$2" = 'false' ]; then | ||||||
| ERL="$ERL -logger handle_otp_reports "$2"" | ||||||
| fi | ||||||
| ;; | ||||||
| --logger-sasl-reports) | ||||||
| I=$(expr $I + 1) | ||||||
| eval "VAL=\${$I}" | ||||||
| if [ "$VAL" = 'true' ] || [ "$VAL" = 'false' ]; then | ||||||
| ERL="$ERL -logger handle_sasl_reports "$VAL"" | ||||||
| S=2 | ||||||
| if [ "$2" = 'true' ] || [ "$2" = 'false' ]; then | ||||||
| ERL="$ERL -logger handle_sasl_reports "$2"" | ||||||
| fi | ||||||
| ;; | ||||||
| --erl) | ||||||
| I=$(expr $I + 1) | ||||||
| eval "VAL=\${$I}" | ||||||
| ERL="$ERL "$VAL"" | ||||||
| S=2 | ||||||
| ERL="$ERL "$2"" | ||||||
| ;; | ||||||
| --erl-config) | ||||||
| S=2 | ||||||
| ERL="$ERL -config "$2"" | ||||||
| ;; | ||||||
| --vm-args) | ||||||
| S=2 | ||||||
| ERL="$ERL -args_file "$2"" | ||||||
| ;; | ||||||
| --boot) | ||||||
| S=2 | ||||||
| ERL="$ERL -boot "$2"" | ||||||
| ;; | ||||||
| --boot-var) | ||||||
| S=3 | ||||||
| ERL="$ERL -boot_var "$2" "$3"" | ||||||
| ;; | ||||||
| --pipe-to) | ||||||
| S=3 | ||||||
| RUN_ERL_PIPE="$2" | ||||||
| if [[ "$RUN_ERL_PIPE" == "-"* ]]; then | ||||||
| echo "--pipe-to : PIPEDIR cannot be a switch" >&2 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| RUN_ERL_LOG="$3" | ||||||
| if [[ "$RUN_ERL_LOG" == "-"* ]]; then | ||||||
| echo "--pipe-to : LOGDIR cannot be a switch" >&2 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Erlang refers to those and other environment variables without snake case so I am going with their convention for now. |
||||||
| exit 1 | ||||||
| fi | ||||||
| ;; | ||||||
| --werl) | ||||||
| USE_WERL=true | ||||||
| ;; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these options in this sections can be sorted alphabetically |
||||||
| *) | ||||||
| while [ $I -le $LENGTH ]; do | ||||||
| I=$(($I + 1)) | ||||||
| set -- "$@" "$1" | ||||||
| shift | ||||||
| done | ||||||
| break | ||||||
| ;; | ||||||
| esac | ||||||
| I=$(expr $I + $S) | ||||||
|
|
||||||
| I=$(($I + $S)) | ||||||
| shift $S | ||||||
| done | ||||||
|
|
||||||
| SELF=$(readlink_f "$0") | ||||||
| SCRIPT_PATH=$(dirname "$SELF") | ||||||
| ERTS_BIN="" | ||||||
|
|
||||||
| if [ "$OSTYPE" = "cygwin" ]; then SCRIPT_PATH=$(cygpath -m "$SCRIPT_PATH"); fi | ||||||
| if [ "$MODE" != "iex" ]; then ERL="-noshell -s elixir start_cli $ERL"; fi | ||||||
|
|
||||||
| if [ "$OS" != "Windows_NT" ]; then | ||||||
| if test -t 1 -a -t 2; then ERL="-elixir ansi_enabled true $ERL"; fi | ||||||
| else | ||||||
| if [ $USE_WERL ]; then ERL_EXEC="werl"; fi | ||||||
| fi | ||||||
|
|
||||||
| if [ "$OS" = "Windows_NT" ] && [ $USE_WERL ]; then | ||||||
| ERL_EXEC="werl" | ||||||
| set -- "$ERTS_BIN$ERL_EXEC" -pa "$SCRIPT_PATH"/../lib/*/ebin $ELIXIR_ERL_OPTIONS $ERL -extra "$@" | ||||||
|
|
||||||
| if [ -n "$RUN_ERL_PIPE" ]; then | ||||||
| mkdir -p "$RUN_ERL_PIPE" | ||||||
| mkdir -p "$RUN_ERL_LOG" | ||||||
| ERL_EXEC="run_erl" | ||||||
| set -- "$ERTS_BIN$ERL_EXEC" -daemon "$RUN_ERL_PIPE/" "$RUN_ERL_LOG/" "$(printf "%q " "$@")" | ||||||
| export HEART_COMMAND=${HEART_COMMAND:-$(printf "%q " "$@")} | ||||||
| fi | ||||||
|
|
||||||
| exec "$ERL_EXEC" -pa "$SCRIPT_PATH"/../lib/*/ebin $ELIXIR_ERL_OPTIONS $ERL -extra "$@" | ||||||
| exec "$@" | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's separate words with an underscore