summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Mike Burns <mike@mike-burns.com>2014-05-30 14:17:32 +0200
committerGravatar Mike Burns <mike@mike-burns.com>2014-05-30 14:58:57 +0200
commit19b5663b9ef06a800831d09a3cbceb937923429d (patch)
tree78bf483d7418e5a4f4b9e922f1dd9ee3c4be967e
parentcda41b5f2a5e9ab38e340f802503c745f77e681e (diff)
On bad args, show usage and exit
The lsrc(1), mkrc(1), rcup(1), and rcdn(1) commands will now print a usage message and exit immediately (with 64, `EX_USAGE`) when given an option it does not understand. This includes `--version` and `--help`. Normal `-h` will print usage and exit successfully, as normal. Closes #59.
-rw-r--r--NEWS.md.in2
-rwxr-xr-xbin/lsrc.in3
-rwxr-xr-xbin/mkrc.in5
-rwxr-xr-xbin/rcdn.in3
-rwxr-xr-xbin/rcup.in3
-rw-r--r--test/lsrc-usage.t7
-rw-r--r--test/mkrc-usage.t11
-rw-r--r--test/rcup-usage.t7
8 files changed, 34 insertions, 7 deletions
diff --git a/NEWS.md.in b/NEWS.md.in
index e858f46..8efa902 100644
--- a/NEWS.md.in
+++ b/NEWS.md.in
@@ -1,5 +1,7 @@
rcm (@PACKAGE_VERSION@) unstable; urgency=low
+ * Show usage information when given bad arguments (Mike Burns).
+
-- Mike Burns <mburns@thoughtbot.com> Fri, 09 May 2014 14:17:49 +0200
rcm (1.2.3) unstable; urgency=low
diff --git a/bin/lsrc.in b/bin/lsrc.in
index 951f3df..ec900a2 100755
--- a/bin/lsrc.in
+++ b/bin/lsrc.in
@@ -229,7 +229,7 @@ handle_command_line() {
local symlink_dirs=
local hostname=
- while getopts FVqvhI:x:B:S:t:d: opt; do
+ while getopts :FVqvhI:x:B:S:t:d: opt; do
case "$opt" in
F) show_sigils=1;;
h) show_help ;;
@@ -242,6 +242,7 @@ handle_command_line() {
x) excludes="$excludes $OPTARG";;
S) symlink_dirs="$symlink_dirs $OPTARG";;
B) hostname="$OPTARG";;
+ ?) show_help 64 ;;
esac
done
shift $(($OPTIND-1))
diff --git a/bin/mkrc.in b/bin/mkrc.in
index 9af0b6a..6545e55 100755
--- a/bin/mkrc.in
+++ b/bin/mkrc.in
@@ -30,7 +30,7 @@ show_help() {
}
if [ $# -eq 0 ]; then
- show_help 1
+ show_help 64
fi
for DOTFILES_DIR in $DOTFILES_DIRS $DEFAULT_DOTFILES_DIR; do
@@ -46,7 +46,7 @@ always_copy=0
force_symlink=0
install_args=
-while getopts ChSsVvqot:d:B: opt; do
+while getopts :ChSsVvqot:d:B: opt; do
case "$opt" in
C) always_copy=1 ;;
h) show_help ;;
@@ -63,6 +63,7 @@ while getopts ChSsVvqot:d:B: opt; do
hostname="$OPTARG"
install_args="-B $hostname"
;;
+ ?) show_help 64 ;;
esac
done
shift $(($OPTIND-1))
diff --git a/bin/rcdn.in b/bin/rcdn.in
index 0393f4d..1179b97 100755
--- a/bin/rcdn.in
+++ b/bin/rcdn.in
@@ -39,7 +39,7 @@ handle_command_line() {
local symlink_dirs=
local hostname=
- while getopts VqvhI:x:S:t:d:B: opt; do
+ while getopts :VqvhI:x:S:t:d:B: opt; do
case "$opt" in
h) show_help ;;
B) hostname="$OPTARG" ;;
@@ -53,6 +53,7 @@ handle_command_line() {
d) dotfiles_dirs="$dotfiles_dirs $OPTARG" ;;
V) version=1 ;;
x) excludes="$excludes $OPTARG" ;;
+ ?) show_help 64 ;;
esac
done
shift $(($OPTIND-1))
diff --git a/bin/rcup.in b/bin/rcup.in
index 17516b6..24d7177 100755
--- a/bin/rcup.in
+++ b/bin/rcup.in
@@ -107,7 +107,7 @@ handle_command_line() {
local hostname=
REPLACE_ALL=0
- while getopts CVqvfhikKI:x:S:t:d:B: opt; do
+ while getopts :CVqvfhikKI:x:S:t:d:B: opt; do
case "$opt" in
B) hostname="$OPTARG" ;;
C) always_copy=1 ;;
@@ -124,6 +124,7 @@ handle_command_line() {
v) verbosity=$(($verbosity + 1)) ;;
V) version=1 ;;
x) excludes="$excludes $OPTARG" ;;
+ ?) show_help 64 ;;
esac
done
shift $(($OPTIND-1))
diff --git a/test/lsrc-usage.t b/test/lsrc-usage.t
index 83c9c21..1e01993 100644
--- a/test/lsrc-usage.t
+++ b/test/lsrc-usage.t
@@ -5,3 +5,10 @@
$ lsrc -h
Usage: lsrc [-FhqVv] [-B HOSTNAME] [-d DOT_DIR] [-I EXCL_PAT] [-S EXCL_PAT ] [-t TAG] [-x EXCL_PAT]
see lsrc(1) and rcm(7) for more details
+
+Unsupported options should output usage information and exit EX_USAGE
+
+ $ lsrc --version
+ Usage: lsrc [-FhqVv] [-B HOSTNAME] [-d DOT_DIR] [-I EXCL_PAT] [-S EXCL_PAT ] [-t TAG] [-x EXCL_PAT]
+ see lsrc(1) and rcm(7) for more details
+ [64]
diff --git a/test/mkrc-usage.t b/test/mkrc-usage.t
index d4f4a9f..4649152 100644
--- a/test/mkrc-usage.t
+++ b/test/mkrc-usage.t
@@ -1,14 +1,21 @@
$ . "$TESTDIR/helper.sh"
-no arguments should output usage information and exit 1
+no arguments should output usage information and exit EX_USAGE
$ mkrc
Usage: mkrc [-ChSsVvqo] [-t TAG] [-d DIR] [-B HOSTNAME] FILES ...
see mkrc(1) and rcm(7) for more details
- [1]
+ [64]
-h should output usage information and exit 0
$ mkrc -h
Usage: mkrc [-ChSsVvqo] [-t TAG] [-d DIR] [-B HOSTNAME] FILES ...
see mkrc(1) and rcm(7) for more details
+
+Unsupported options should output usage information and exit EX_USAGE
+
+ $ mkrc --version
+ Usage: mkrc [-ChSsVvqo] [-t TAG] [-d DIR] [-B HOSTNAME] FILES ...
+ see mkrc(1) and rcm(7) for more details
+ [64]
diff --git a/test/rcup-usage.t b/test/rcup-usage.t
index 1fa8a5a..336c668 100644
--- a/test/rcup-usage.t
+++ b/test/rcup-usage.t
@@ -5,3 +5,10 @@
$ rcup -h
Usage: rcup [-CfhiKkqVv] [-B HOSTNAME] [-d DOT_DIR] [-I EXCL_PAT] [-S EXCL_PAT] [-t TAG] [-x EXCL_PAT]
see rcup(1) and rcm(7) for more details
+
+Unsupported options should output usage information and exit EX_USAGE
+
+ $ rcup --version
+ Usage: rcup [-CfhiKkqVv] [-B HOSTNAME] [-d DOT_DIR] [-I EXCL_PAT] [-S EXCL_PAT] [-t TAG] [-x EXCL_PAT]
+ see rcup(1) and rcm(7) for more details
+ [64]