Skip to content

Commit

Permalink
print usage to stderr if wrong argument detected
Browse files Browse the repository at this point in the history
  • Loading branch information
dongyx committed May 29, 2022
1 parent 3d25442 commit e1f0744
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install: all
$(libdir)/shsub \
$(mandir)/man1
$(INSTALL) cli tc $(libdir)/shsub/
$(INSTALL) -m644 usage version LICENSE $(libdir)/shsub/
$(INSTALL) -m644 version LICENSE $(libdir)/shsub/
$(INSTALL) -m644 shsub.1 $(mandir)/man1/
@echo generate "`echo $(bindir)/shsub`"
@>$(bindir)/shsub
Expand Down
23 changes: 17 additions & 6 deletions cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@

set -e
dir=`dirname -- "$0"`
usage="$dir/usage"
version="$dir/version"
license="$dir/LICENSE"
tc="$dir/tc"

help() {
cat <<\.
usage: shsub [<options>] [<file>]
if <file> is omitted, read from stdin.
options:
-s <sh> specify the shell to execute the compiled script,
`/bin/sh' by default
-h print the brief usage
-v print the version information
.
}
# shell escape
shesc() {
printf %s "$1" | sed "s/'/'\\\\''/g; 1 s/^/'/; $ s/$/'/"
Expand All @@ -23,13 +35,12 @@ sh=/bin/sh
while getopts 's:hv' opt; do
case $opt in
s) sh="$OPTARG";;
h) cat "$usage";
h) help
exit;;
v) echo shsub "`cat "$version"`";
cat "$license";
v) echo shsub "`cat "$version"`"
cat "$license"
exit;;
?) echo type \`shsub -h\' for the brief usage
echo 'read the man page shsub(1) for detail'
?) help >&2
exit 1;;
esac
done
Expand Down
12 changes: 0 additions & 12 deletions usage

This file was deleted.

2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.0
1.4.0-dev

0 comments on commit e1f0744

Please sign in to comment.