Skip to content

Instantly share code, notes, and snippets.

@kparkov
Created August 27, 2018 14:15
Show Gist options
  • Save kparkov/2353488a60e1094d9482d6a7cf2a5869 to your computer and use it in GitHub Desktop.
Save kparkov/2353488a60e1094d9482d6a7cf2a5869 to your computer and use it in GitHub Desktop.
Bash CLI interface with subcommands
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