Last active
June 25, 2021 13:31
-
-
Save cakyus/f5edb48d108987c7cc5757a21d0b9a97 to your computer and use it in GitHub Desktop.
make in bash
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
#!/bin/sh | |
# | |
# This program is free software; you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License version 2 | |
# as published by the Free Software Foundation. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program; if not, write to the Free Software | |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
# MA 02110-1301, USA. | |
# | |
# -- Write Your Code Here ---------------------------------------------- | |
# DOC help - Print this information | |
# DOC.help Print this information | |
# DOC.help Arguments: | |
# DOC.help [command] Print help on a command | |
make_help(){ | |
if [ $# -eq 1 ]; then | |
grep "^# DOC.$1 " $0 | cut -d ' ' -f 3- | |
return 0 | |
fi | |
echo "Usage: <command> [argument..]" | |
echo "" | |
echo "Commands:" | |
grep '^# DOC ' $0 | cut -d ' ' -f 3- | |
echo "" | |
echo "Type 'help <comand>' for help on a command" | |
return 0 | |
} | |
info(){ | |
>&2 echo $(date +'%H:%M:%S')" INFO "$@ | |
} | |
warn(){ | |
>&2 echo $(date +'%H:%M:%S')" WARN "$@ | |
} | |
debug(){ | |
if [ ! -z "$MAKE_TRACE" ]; then | |
if [ "$MAKE_TRACE" = "1" ]; then | |
>&2 echo $(date +'%H:%M:%S')" DEBUG "$@ | |
fi | |
fi | |
} | |
set -e | |
COMMAND_NAME=make_help | |
OPTION_VERBOSE=0 | |
ARGV=$(getopt -a -n alphabet -o vh --long help,verbose -- "$@") | |
if [ $? -ne 0 ]; then | |
make_help | |
exit 1 | |
fi | |
eval set -- "$ARGV" | |
while true ; do | |
case "$1" in | |
-h|--help) make_help ; exit 0 ;; | |
-v|--verbose) OPTION_VERBOSE=1 ; shift 2;; | |
--) shift ; break ;; | |
*) make_help ; exit 1 ;; | |
esac | |
done | |
echo $1 | |
$COMMAND_NAME $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment