Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve messaging for the wrong usage #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions ch
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@
# catch uninitialized variables
set -u


# display basic usage information
display_basic_usage ()
{
echo "Usage: $0 <command> [options]"
echo "Try '$0 --help' for more information."
}


# display detailed usage information
display_detailed_usage ()
{
echo "Usage: $0 <command> [options]"
echo "Extract help information for a given command and its options."
echo
echo "Options:"
echo " --help Show this help message and exit."
echo
echo "Examples:"
echo " $0 ls --help"
echo " $0 grep --invert-match"
exit 0
}


###############################################
# extract from line starting with search word
# upto newline or line starting with -
Expand All @@ -24,6 +49,15 @@ extract_text ()
}


# Check for help option or no arguments
if [[ "$#" -eq 0 ]]; then
display_basic_usage
exit 1
elif [[ "$1" == "--help" ]]; then
display_detailed_usage
fi


###############################################
# variable to save command name
# shift, for rest of arguments to be looped
Expand Down