Skip to content

Commit

Permalink
Add short option -h
Browse files Browse the repository at this point in the history
It's a classic.
It's a shame it took me almost two decades to add it.
  • Loading branch information
aureliojargas committed Mar 26, 2020
1 parent 1394558 commit 0a7127a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ v0.9 beta (unreleased):
- Fixed to work properly in bash5 (tks Yanmarshus Bachtiar)
- Fixed eval bug when running in bash3 or newer (tks Marcus Habermehl)
- New tests for all the command line options (cmdline.md)
- Added short option -h (for --help)
- Converted everything (code and docs) to UTF-8
- Improved the source code formatting, now it is readable
- Now using shellcheck to improve code quality
Expand Down
9 changes: 6 additions & 3 deletions cmdline.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ $ alias txt2regex="bash ./txt2regex.sh"
$
```

## Option --help
## Options -h, --help

```console
$ txt2regex --help
$ txt2regex --help | tee help.txt
usage: txt2regex [ --nocolor | --whitebg ] [ --all | --prog PROGRAMS ]
txt2regex --showmeta
txt2regex --showinfo PROGRAM [ --nocolor ]
Expand All @@ -36,9 +36,12 @@ OPTIONS (they are default OFF):
--make LABEL Prints the default regex for the specified label

--version Prints the program version and quit
--help Prints the help message and quit
-h, --help Prints the help message and quit

Please read the program Man Page for more information.
$ txt2regex -h > h.txt
$ diff help.txt h.txt
$ rm help.txt h.txt
$
```

Expand Down
4 changes: 2 additions & 2 deletions txt2regex.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Usage(){
printf '%s\n' $" --make LABEL Prints the default regex for the specified label"
printf '\n'
printf '%s\n' $" --version Prints the program version and quit"
printf '%s\n' $" --help Prints the help message and quit"
printf '%s\n' $" -h, --help Prints the help message and quit"
printf '\n'
printf '%s\n' $"Please read the program Man Page for more information."
exit "${1:-0}" # $1 is the exit code (default is 0)
Expand Down Expand Up @@ -268,7 +268,7 @@ do
printf 'txt2regex v%s\n' "$VERSION"
exit 0
;;
--help)
-h | --help)
Usage 0
;;
*)
Expand Down

0 comments on commit 0a7127a

Please sign in to comment.