Skip to content

Commit

Permalink
Better --version output: cross OS output; move --help/version into se…
Browse files Browse the repository at this point in the history
…parate functions
  • Loading branch information
ekalinin committed Mar 27, 2022
1 parent 5d0d6e5 commit 8f91bd0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 deletions.
69 changes: 41 additions & 28 deletions gh-md-toc
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,45 @@ gh_toc_get_filename() {
echo "${1##*/}"
}

show_version() {
echo "$gh_toc_version"
echo
echo "os: `uname -s`"
echo "arch: `uname -m`"
echo "kernel: `uname -r`"
echo "shell: `$SHELL --version`"
echo
for tool in curl wget grep awk sed; do
printf "%-5s: " $tool
if `type $tool &>/dev/null`; then
echo `$tool --version | head -n 1`
else
echo "not installed"
fi
done
}

show_help() {
local app_name=$(basename "$0")
echo "GitHub TOC generator ($app_name): $gh_toc_version"
echo ""
echo "Usage:"
echo " $app_name [options] src [src] Create TOC for a README file (url or local path)"
echo " $app_name - Create TOC for markdown from STDIN"
echo " $app_name --help Show help"
echo " $app_name --version Show version"
echo ""
echo "Options:"
echo " --indent <NUM> Set indent size. Default: 3."
echo " --insert Insert new TOC into original file. For local files only. Default: false."
echo " See https://github.com/ekalinin/github-markdown-toc/issues/41 for details."
echo " --no-backup Remove backup file. Set --insert as well. Defaul: false."
echo " --hide-footer Do not write date & author of the last TOC update. Set --insert as well. Default: false."
echo " --skip-header Hide entry of the topmost headlines. Default: false."
echo " See https://github.com/ekalinin/github-markdown-toc/issues/125 for details."
echo ""
}

#
# Options handlers
#
Expand All @@ -299,38 +338,12 @@ gh_toc_app() {
local indent=3

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

if [ "$1" = '--version' ]; then
echo "$gh_toc_version"
echo
echo "os: `lsb_release -d | cut -f 2`"
echo "kernel: `cat /proc/version`"
echo "shell: `$SHELL --version`"
echo
for tool in curl wget grep awk sed; do
printf "%-5s: " $tool
echo `$tool --version | head -n 1`
done
show_version
return
fi

Expand Down
2 changes: 2 additions & 0 deletions tests/tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ test_help() {
run $BATS_TEST_DIRNAME/../gh-md-toc --version
assert_success
assert_equal "${lines[0]}" "0.8.0"
assert_equal "${lines[1]}" "os: `uname -s`"
assert_equal "${lines[2]}" "arch: `uname -m`"
}

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

0 comments on commit 8f91bd0

Please sign in to comment.