Skip to content

Commit

Permalink
Exit with 1 and a message when -a and -n are both provided
Browse files Browse the repository at this point in the history
  • Loading branch information
smashwilson committed Mar 22, 2019
1 parent 3726529 commit 2526e69
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
35 changes: 32 additions & 3 deletions atom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,20 @@ esac

export ATOM_DISABLE_SHELLING_OUT_FOR_ENVIRONMENT=true

while getopts ":wtfvh-:" opt; do
ATOM_ADD=false
ATOM_NEW_WINDOW=false
EXIT_CODE_OVERRIDE=

while getopts ":anwtfvh-:" opt; do
case "$opt" in
-)
case "${OPTARG}" in
add)
ATOM_ADD=true
;;
new-window)
ATOM_NEW_WINDOW=true
;;
wait)
WAIT=1
;;
Expand All @@ -45,6 +55,12 @@ while getopts ":wtfvh-:" opt; do
;;
esac
;;
a)
ATOM_ADD=true
;;
n)
ATOM_NEW_WINDOW=true
;;
w)
WAIT=1
;;
Expand All @@ -58,6 +74,11 @@ while getopts ":wtfvh-:" opt; do
esac
done

if [ "${ATOM_ADD}" = "true" ] && [ "${ATOM_NEW_WINDOW}" = "true" ]; then
EXPECT_OUTPUT=1
EXIT_CODE_OVERRIDE=1
fi

if [ $REDIRECT_STDERR ]; then
exec 2> /dev/null
fi
Expand Down Expand Up @@ -115,7 +136,11 @@ if [ $OS == 'Mac' ]; then

if [ $EXPECT_OUTPUT ]; then
"$ATOM_PATH/$ATOM_APP_NAME/Contents/MacOS/$ATOM_EXECUTABLE_NAME" --executed-from="$(pwd)" --pid=$$ "$@"
exit $?
if [ $? -eq 0 ] && [ -n "${EXIT_CODE_OVERRIDE}" ]; then
exit "${EXIT_CODE_OVERRIDE}"
else
exit $?
fi
else
open -a "$ATOM_PATH/$ATOM_APP_NAME" -n --args --executed-from="$(pwd)" --pid=$$ --path-environment="$PATH" "$@"
fi
Expand Down Expand Up @@ -144,7 +169,11 @@ elif [ $OS == 'Linux' ]; then

if [ $EXPECT_OUTPUT ]; then
"$ATOM_PATH" --executed-from="$(pwd)" --pid=$$ "$@"
exit $?
if [ $? -eq 0 ] && [ -n "${EXIT_CODE_OVERRIDE}" ]; then
exit "${EXIT_CODE_OVERRIDE}"
else
exit $?
fi
else
(
nohup "$ATOM_PATH" --executed-from="$(pwd)" --pid=$$ "$@" > "$ATOM_HOME/nohup.out" 2>&1
Expand Down
10 changes: 10 additions & 0 deletions src/main-process/parse-command-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ module.exports = function parseCommandLine (processArgs) {
executedFrom = process.cwd()
}

if (newWindow && addToLastWindow) {
process.stderr.write(
`Only one of the --add and --new-window options may be specified at the same time.\n\n${options.help()}`,
)

// Exiting the main process with a nonzero exit code on MacOS causes the app open to fail with the mysterious
// message "LSOpenURLsWithRole() failed for the application /Applications/Atom Dev.app with error -10810."
process.exit(0)
}

let pidToKillWhenClosed = null
if (args['wait']) {
pidToKillWhenClosed = args['pid']
Expand Down

0 comments on commit 2526e69

Please sign in to comment.