diff options
author | Alejandro Colomar <alx.manpages@gmail.com> | 2022-05-11 19:51:46 +0200 |
---|---|---|
committer | Alejandro Colomar <alx.manpages@gmail.com> | 2022-05-11 21:19:04 +0200 |
commit | 06a6f7b4582fcf0209d0b78b267ca5daab2a6731 (patch) | |
tree | bc5ae2ddab47ba53c64464ab83c03a9deca6f345 /bin | |
parent | 8c691b0ce92fb079154544d79673f678195d98f1 (diff) |
grepc, grepc.1: -h: Add option to print the usage message.
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/grepc | 50 |
1 files changed, 38 insertions, 12 deletions
@@ -1,10 +1,34 @@ #!/bin/sh -if [ $# -ne 1 ]; then - >&2 echo "Usage: $0 IDENTIFIER"; - exit 1; -fi; +grepc_usage() +{ + echo "Usage: $0 [OPTION] IDENTIFIER"; +} + + +grepc_parse_cmd() +{ + while getopts "h" opt; do + case "$opt" in + h) + grepc_usage; + exit 0; + ;; + ?) + grepc_usage >&2; + exit 1; + ;; + esac; + done; + shift $(($OPTIND-1)); + + if [ $# -ne 1 ]; then + grepc_usage >&2; + exit 1; + fi; + identifier=$1; +} grepc_find_files() @@ -180,15 +204,17 @@ grepc_type() main() { - grepc_find_files "$1"; + grepc_parse_cmd $@; + + grepc_find_files "$identifier"; - grepc_macro "$1"; - grepc_enum_constant "$1"; - grepc_func "$1"; - grepc_linux "$1"; - grepc_glibc "$1"; - grepc_type "$1"; + grepc_macro "$identifier"; + grepc_enum_constant "$identifier"; + grepc_func "$identifier"; + grepc_linux "$identifier"; + grepc_glibc "$identifier"; + grepc_type "$identifier"; } -main "$1"; +main $@; |