Skip to content

Commit 650b8a6

Browse files
authored
Improve help menus (#3)
1 parent 133c335 commit 650b8a6

File tree

3 files changed

+51
-39
lines changed

3 files changed

+51
-39
lines changed

Makefile

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
# synonym
1+
.PHONY: install uninstall linter
2+
SCRIPT := synonym
23

34
install:
4-
cp synonym /usr/local/bin/synonym
5-
chmod 755 /usr/local/bin/synonym
5+
cp synonym /usr/local/bin/$(SCRIPT)
6+
chmod 755 /usr/local/bin/$(SCRIPT)
67

78
uninstall:
8-
rm -f /usr/local/bin/synonym
9+
rm -f /usr/local/bin/$(SCRIPT)
10+
11+
linter:
12+
shellcheck ./$(SCRIPT)

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,16 @@ You are now all set-up to run synonym in your terminal.
9292
```console
9393
$ synonym -u
9494
Usage: synonym [OPTION] WORD
95-
Finds all synonyms for a specific word in a specified language.
95+
96+
Finds synonyms for a given word in a specified language.
97+
Run synonym -i for more information.
9698

9799
Options:
98100
-l LANG Finds all synonyms for this specific language.
99101
Languages supported: en, fr, cs, el, es, da, de,
100102
hu, it, no, pl, pt, ro, ru, sk
101103
-h Show help message and exit.
102-
-u Show usage and exit.
104+
-i Show more help information and exit.
103105
-v Show program version number and exit.
104106
```
105107

synonym

+39-33
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
# SOFTWARE.
2424

25-
# Print out synonyms.
25+
# Finds synonyms for a given word in a specified language.
2626
#
2727
# Dependencies: jq
2828
#
@@ -31,7 +31,25 @@
3131
set -e
3232

3333
self=${0##*/}
34-
version="$self v1.4.2"
34+
version="$self v1.4.3"
35+
36+
_help() {
37+
cat <<EOF
38+
Usage: $self [OPTION] WORD
39+
40+
Finds synonyms for a given word in a specified language.
41+
Run $self -i for more information.
42+
43+
Options:
44+
-l LANG Finds all synonyms for this specific language.
45+
Languages supported: en, fr, cs, el, es, da, de,
46+
hu, it, no, pl, pt, ro, ru, sk
47+
-h Show help message and exit.
48+
-i Show more help information and exit.
49+
-v Show program version number and exit.
50+
51+
EOF
52+
}
3553

3654
_info() {
3755
cat <<EOF
@@ -42,6 +60,7 @@ List of languages supported: en, fr, cs, el, es, da, de, hu, it,
4260
no, pl, pt, ro, ru, sk
4361
4462
Requirements to run $self:
63+
============================
4564
4665
- Thesaurus API key from https://thesaurus.altervista.org/mykey
4766
- jq https://stedolan.github.io/jq/download/
@@ -57,6 +76,7 @@ In this file, you can chose a default language and you will need
5776
to input your API key.
5877
5978
.synonymrc example:
79+
===================
6080
6181
# API KEY from https://thesaurus.altervista.org/mykey
6282
SYNONYM_THESAURUS_KEY=<API KEY>
@@ -67,35 +87,22 @@ to input your API key.
6787
# it, no, pl, pt, ro, ru, sk
6888
SYNONYM_SEARCH_LANG=en
6989
70-
Note:
90+
Notes:
91+
======
7192
7293
If no language is set in .synonymrc, or specified in parameters,
7394
the default language will be fetched from the os (\$LANGUAGE or
7495
\$LANG). If not supported, or null, it will be set as default to
7596
en_US.
7697
98+
---
99+
77100
Copyright 2020 Matthieu Petiteau, all rights reserved.
78101
$version
79102
80103
EOF
81104
}
82105

83-
_usage() {
84-
cat <<EOF
85-
Usage: $self [OPTION] WORD
86-
Finds all synonyms for a specific word in a specified language.
87-
88-
Options:
89-
-l LANG Finds all synonyms for this specific language.
90-
Languages supported: en, fr, cs, el, es, da, de,
91-
hu, it, no, pl, pt, ro, ru, sk
92-
-h Show help message and exit.
93-
-u Show usage and exit.
94-
-v Show program version number and exit.
95-
96-
EOF
97-
}
98-
99106
# Compute response from the API.
100107
_compute() {
101108
# Check for any erros.
@@ -165,7 +172,7 @@ _language_index() {
165172
*)
166173
printf '%s\n%s\n' \
167174
"Error: Language $1 not supported." \
168-
"Run $self -u for usage and see the list of supported languages." >&2
175+
"Run $self -i for more information and see the list of supported languages." >&2
169176
exit 1
170177
;;
171178
esac
@@ -205,8 +212,8 @@ _init() {
205212
done
206213

207214
printf '%s\n%s\n' \
208-
'Error: synonymrc file not found' \
209-
"Run $self -h for help." >&2
215+
'Error: .synonymrc file not found.' \
216+
"Run $self -i for setup information." >&2
210217
exit 1
211218
}
212219

@@ -219,19 +226,19 @@ command -v jq >/dev/null 2>&1 || {
219226
}
220227

221228
# Params
222-
options=":l:huv"
229+
options=":l:hiv"
223230
while getopts "$options" option; do
224231
case "$option" in
225232
l)
226233
_synonym_language=$(_language_index "$OPTARG")
227234
;;
228235
h)
229-
_info
230-
_usage
236+
_help
231237
exit 0
232238
;;
233-
u)
234-
_usage
239+
i)
240+
_info
241+
_help
235242
exit 0
236243
;;
237244
v)
@@ -240,7 +247,7 @@ while getopts "$options" option; do
240247
;;
241248
\?)
242249
printf 'Error: invalid option: -%s\n' "$OPTARG" >&2
243-
_usage
250+
_help
244251
exit 1
245252
;;
246253
esac
@@ -251,15 +258,14 @@ _searched_word="$1"
251258
_init
252259

253260
[[ -z $_searched_word ]] && {
254-
printf '%s\n%s\n' \
255-
'Error: Missing word to search.' \
256-
"Run $self -u for usage." >&2
261+
printf 'Error: Missing word to search.\n' >&2
262+
_help
257263
exit 1
258264
}
259265
[[ -z $SYNONYM_THESAURUS_KEY ]] && {
260266
printf '%s\n%s\n' \
261-
'Error: api key not found in synonymrc.' \
262-
"Run $self -h for help." >&2
267+
'Error: API key not found in synonymrc.' \
268+
"Run $self -i for setup information." >&2
263269
exit 1
264270
}
265271
[[ -z $_synonym_language ]] && _synonym_language="$(_get_language)"

0 commit comments

Comments
 (0)