Bisa / factorio-init

Factorio init script
MIT License
415 stars 82 forks source link

add a command to allowing source'ing the script to import vars etc. #126

Closed N-Coder closed 6 years ago

N-Coder commented 6 years ago

This adds the command 'source' that prevents the final call to exit by just returning successfully (i.e. return 0), so that other scripts (possibly with set -e) may source this script and thus import all our variables and functions. This makes the logic for finding important factorio files and all functions defined in this script easily reusable. By calling exit, other scripts using source to import this script would be terminated.

This can be seen when running the following snippet (which will never print "post-source with other arg"):

#!/usr/bin/env bash

set -e

echo "pre-source with source arg"
source factorio source
echo "post-source with source arg"

echo "$CMDOUT"

echo "pre-source with other arg"
source factorio version
echo "post-source with other arg"

echo "$CMDOUT"