Created
August 27, 2018 14:15
-
-
Save kparkov/2353488a60e1094d9482d6a7cf2a5869 to your computer and use it in GitHub Desktop.
Bash CLI interface with subcommands
This file contains 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
command="${1: }" | |
arguments="${@:2}" | |
case ${command} in | |
-h) | |
help | |
;; | |
--help) | |
help | |
;; | |
help) | |
if [[ -z "${2: }" ]] | |
then | |
help | |
else | |
./scripts/commands/${2}.sh help | |
fi | |
;; | |
"") | |
help | |
;; | |
*) | |
if contains "$command" "$(commands)" | |
then | |
./scripts/commands/$command.sh $arguments | |
else | |
echo "" | |
echo -e " $(red Error): Unknown command '$command'" | |
help | |
fi | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment