@@ -28,15 +28,34 @@ redPrint() {
2828}
2929
3030die () {
31- redPrint " Error: $* " >&2
32- exit 1
33- }
31+ local prompt_help=false exit_staus=2
32+ while (( $# > 0 )) ; do
33+ case " $1 " in
34+ -h)
35+ prompt_help=true
36+ shift
37+ ;;
38+ -s)
39+ exit_staus=$2
40+ shift 2
41+ ;;
42+ * )
43+ break
44+ ;;
45+ esac
46+ done
47+
48+ (( $# > 0 )) && redPrint " $PROG : $* "
49+ $prompt_help && echo " Try '$PROG --help' for more information."
50+
51+ exit " $exit_staus "
52+ } >&2
3453
3554isAbsolutePath () {
3655 [[ " $1 " =~ ^/ ]]
3756}
3857
39- # `realpath` command existed on Linux and macOS, return resolved physical path
58+ # `realpath` command exists on Linux and macOS, return resolved physical path
4059# - realpath command on macOS do NOT support option `-e`;
4160# combined `[ -e $file ]` to check file existence first.
4261# - How can I get the behavior of GNU's readlink -f on a Mac?
@@ -46,14 +65,7 @@ realpath() {
4665}
4766
4867usage () {
49- local -r exit_code=${1:- 0}
50- (( $# > 0 )) && shift
51- local -r out=$(( (exit_code != 0 ) + 1 ))
52-
53- # NOTE: $'foo' is the escape sequence syntax of bash
54- (( $# > 0 )) && redPrint " $* " $' \n ' >& " $out "
55-
56- cat >& " $out " << EOF
68+ cat << EOF
5769Usage: $PROG [OPTION]... command [command-args]...
5870
5971Copy the command into docker container
@@ -82,7 +94,7 @@ miscellaneous:
8294 -V, --version display version information and exit
8395EOF
8496
85- exit " $exit_code "
97+ exit
8698}
8799
88100progVersion () {
@@ -140,7 +152,7 @@ while (($# > 0)); do
140152 break
141153 ;;
142154 -* )
143- usage 2 " $PROG : unrecognized option '$1 '"
155+ die -h " unrecognized option '$1 '"
144156 ;;
145157 * )
146158 # if not option, treat all follow arguments as command
153165readonly container_name docker_user docker_workdir docker_tmpdir docker_command_cp_path verbose args
154166
155167[ -n " $container_name " ] ||
156- usage 1 " No destination docker container name, specified by option -c/--container!"
168+ die -h " requires destination docker container name, specified by option -c/--container!"
157169
158170if [ -n " $docker_workdir " ]; then
159171 isAbsolutePath " $docker_workdir " ||
171183# check docker command existence
172184# #######################################
173185
174- command -v docker & > /dev/null || die ' docker command not found!'
186+ type -P docker & > /dev/null || die ' docker command not found!'
175187
176188# #######################################
177189# prepare vars for docker operation
0 commit comments