Skip to content

Instantly share code, notes, and snippets.

@peakBreaker
Last active October 11, 2018 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peakBreaker/82dda7eefc73fde657d9926fd4b76e11 to your computer and use it in GitHub Desktop.
Save peakBreaker/82dda7eefc73fde657d9926fd4b76e11 to your computer and use it in GitHub Desktop.
Handle bash CLI args
#!/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