Last active
October 11, 2018 08:26
-
-
Save peakBreaker/82dda7eefc73fde657d9926fd4b76e11 to your computer and use it in GitHub Desktop.
Handle bash CLI args
This file contains hidden or 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
#!/usr/bin/env bash | |
# GET ARGS | |
while getopts ":r:c:o:w:hs:hd" o; do case "${o}" in | |
h) | |
echo -e "Optional arguments for custom use:" | |
echo -e " -r: Repository (local file or url)" | |
echo -e " -c: Config file" | |
echo -e " -o: Output file" | |
echo -e " -w: Worker program to call" | |
echo -e " -d: Enable devmode (no ncurses)" | |
echo -e " -s: simulate the program" | |
echo -e " -h: Show this message" | |
exit | |
;; | |
r) repository=${OPTARG} && git ls-remote "$repository" || exit ;; | |
c) config=${OPTARG} ;; | |
o) output=${OPTARG} ;; | |
w) worker=${OPTARG} ;; | |
s) simulated="true" ;; # Flag, sets var true | |
d) devmode="true" ;; # Flag, sets var true | |
*) echo "-$OPTARG is not a valid option." && exit ;; | |
esac done | |
# DEFAULTS: | |
[ -z ${repository+x} ] && dotfilesrepo="https://github.com/peakbreaker/<repo>.git" | |
[ -z ${config+x} ] && config="https://raw.githubusercontent.com/peakBreaker/PIES/master/progs.csv" | |
[ -z ${output+x} ] && output="output.txt" | |
[ -z ${worker+x} ] && worker="yes" | |
[ -z ${simulated+x} ] && simulated="false" | |
[ -z ${devmode+x} ] && devmode="false" | |
# Example Debug of one of the params | |
echo "devmode is : $devmode" | |
[[ $devmode = "true" ]] && echo "devmode is enabled!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment