Skip to content

Commit 8f91bd0

Browse files
committed
Better --version output: cross OS output; move --help/version into separate functions
1 parent 5d0d6e5 commit 8f91bd0

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

gh-md-toc

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,45 @@ gh_toc_get_filename() {
291291
echo "${1##*/}"
292292
}
293293

294+
show_version() {
295+
echo "$gh_toc_version"
296+
echo
297+
echo "os: `uname -s`"
298+
echo "arch: `uname -m`"
299+
echo "kernel: `uname -r`"
300+
echo "shell: `$SHELL --version`"
301+
echo
302+
for tool in curl wget grep awk sed; do
303+
printf "%-5s: " $tool
304+
if `type $tool &>/dev/null`; then
305+
echo `$tool --version | head -n 1`
306+
else
307+
echo "not installed"
308+
fi
309+
done
310+
}
311+
312+
show_help() {
313+
local app_name=$(basename "$0")
314+
echo "GitHub TOC generator ($app_name): $gh_toc_version"
315+
echo ""
316+
echo "Usage:"
317+
echo " $app_name [options] src [src] Create TOC for a README file (url or local path)"
318+
echo " $app_name - Create TOC for markdown from STDIN"
319+
echo " $app_name --help Show help"
320+
echo " $app_name --version Show version"
321+
echo ""
322+
echo "Options:"
323+
echo " --indent <NUM> Set indent size. Default: 3."
324+
echo " --insert Insert new TOC into original file. For local files only. Default: false."
325+
echo " See https://github.com/ekalinin/github-markdown-toc/issues/41 for details."
326+
echo " --no-backup Remove backup file. Set --insert as well. Defaul: false."
327+
echo " --hide-footer Do not write date & author of the last TOC update. Set --insert as well. Default: false."
328+
echo " --skip-header Hide entry of the topmost headlines. Default: false."
329+
echo " See https://github.com/ekalinin/github-markdown-toc/issues/125 for details."
330+
echo ""
331+
}
332+
294333
#
295334
# Options handlers
296335
#
@@ -299,38 +338,12 @@ gh_toc_app() {
299338
local indent=3
300339

301340
if [ "$1" = '--help' ] || [ $# -eq 0 ] ; then
302-
local app_name=$(basename "$0")
303-
echo "GitHub TOC generator ($app_name): $gh_toc_version"
304-
echo ""
305-
echo "Usage:"
306-
echo " $app_name [options] src [src] Create TOC for a README file (url or local path)"
307-
echo " $app_name - Create TOC for markdown from STDIN"
308-
echo " $app_name --help Show help"
309-
echo " $app_name --version Show version"
310-
echo ""
311-
echo "Options:"
312-
echo " --indent <NUM> Set indent size. Default: 3."
313-
echo " --insert Insert new TOC into original file. For local files only. Default: false."
314-
echo " See https://github.com/ekalinin/github-markdown-toc/issues/41 for details."
315-
echo " --no-backup Remove backup file. Set --insert as well. Defaul: false."
316-
echo " --hide-footer Do not write date & author of the last TOC update. Set --insert as well. Default: false."
317-
echo " --skip-header Hide entry of the topmost headlines. Default: false."
318-
echo " See https://github.com/ekalinin/github-markdown-toc/issues/125 for details."
319-
echo ""
341+
show_help
320342
return
321343
fi
322344

323345
if [ "$1" = '--version' ]; then
324-
echo "$gh_toc_version"
325-
echo
326-
echo "os: `lsb_release -d | cut -f 2`"
327-
echo "kernel: `cat /proc/version`"
328-
echo "shell: `$SHELL --version`"
329-
echo
330-
for tool in curl wget grep awk sed; do
331-
printf "%-5s: " $tool
332-
echo `$tool --version | head -n 1`
333-
done
346+
show_version
334347
return
335348
fi
336349

tests/tests.bats

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ test_help() {
149149
run $BATS_TEST_DIRNAME/../gh-md-toc --version
150150
assert_success
151151
assert_equal "${lines[0]}" "0.8.0"
152+
assert_equal "${lines[1]}" "os: `uname -s`"
153+
assert_equal "${lines[2]}" "arch: `uname -m`"
152154
}
153155

154156
@test "TOC for non-english chars, #6, #10" {

0 commit comments

Comments
 (0)