From 51ebc2570ded7b5e1e6c697ffc006fcf2d027769 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 6 Jun 2017 06:40:41 +1000 Subject: [PATCH] help output --- mdcheckr | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/mdcheckr b/mdcheckr index 2e3bd56..6362fae 100755 --- a/mdcheckr +++ b/mdcheckr @@ -224,10 +224,17 @@ function explain() { >&2 echo -e Warning:$_file:$_line_no:$_message } -# Parse command-line optins -function show_help() { +# Parse command-line optins... +function show_usage() { + cat << EOF +usage: mdcheckr [ -h | --help | -v | --version ] FILE .. +EOF +} + + +function show_help() { + show_usage cat << EOF -usage: mdcheckr [ -h ] FILE .. A testing tool to detect quality problems with your Markdown documentation. @@ -248,8 +255,25 @@ function show_version() { VERSION="1.0" OPTIND=1 VERBOSITY=3 -while getopts hv opt; do +while getopts "hv-:" opt; do case $opt in + -) + case "${OPTARG}" in + help) + show_help + exit 0 + ;; + version) + show_version + exit 0 + ;; + *) + echo "$0: Illegal option -- ${OPTARG}" >&2 + show_usage >&2 + exit 1 + ;; + esac + ;; h) show_help exit 0 @@ -259,13 +283,20 @@ while getopts hv opt; do exit 0 ;; *) - show_help >&2 + show_usage >&2 exit 1 ;; esac done shift "$((OPTIND-1))" +# Require at least one filename to be specified +if [ "$#" -lt 1 ]; then + echo "$0: Missing file operand" >&2 + show_usage >&2 +fi + + # Explicitly check for each dependency for i in which pandoc xmllint curl; do which $i > /dev/null 2> /dev/null || ( >&2 echo "The tool '$i' is required by mdcheckr, but is not in your \$PATH."