Skip to content

Commit 5d0d6e5

Browse files
committed
Better --help output: separate doc for each option;
1 parent 352d7ae commit 5d0d6e5

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

gh-md-toc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,20 @@ gh_toc_app() {
303303
echo "GitHub TOC generator ($app_name): $gh_toc_version"
304304
echo ""
305305
echo "Usage:"
306-
echo " $app_name [--insert] [--hide-footer] [--skip-header] [--indent #spaces] src [src] Create TOC for a README file (url or local path)"
307-
echo " $app_name [--no-backup] [--hide-footer] [--skip-header] [--indent #spaces] src [src] Create TOC without backup, requires <!--ts--> / <!--te--> placeholders"
306+
echo " $app_name [options] src [src] Create TOC for a README file (url or local path)"
308307
echo " $app_name - Create TOC for markdown from STDIN"
309308
echo " $app_name --help Show help"
310309
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 ""
311320
return
312321
fi
313322

@@ -387,4 +396,3 @@ gh_toc_app() {
387396
# Entry point
388397
#
389398
gh_toc_app "$@"
390-

tests/tests.bats

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,31 @@ load test_helper
118118
}
119119
}
120120

121+
test_help() {
122+
assert_equal "${lines[1]}" "Usage:"
123+
assert_equal "${lines[2]}" " gh-md-toc [options] src [src] Create TOC for a README file (url or local path)"
124+
assert_equal "${lines[3]}" " gh-md-toc - Create TOC for markdown from STDIN"
125+
assert_equal "${lines[4]}" " gh-md-toc --help Show help"
126+
assert_equal "${lines[5]}" " gh-md-toc --version Show version"
127+
assert_equal "${lines[6]}" "Options:"
128+
assert_equal "${lines[7]}" " --indent <NUM> Set indent size. Default: 3."
129+
assert_equal "${lines[8]}" " --insert Insert new TOC into original file. For local files only. Default: false."
130+
assert_equal "${lines[10]}" " --no-backup Remove backup file. Set --insert as well. Defaul: false."
131+
assert_equal "${lines[11]}" " --hide-footer Do not write date & author of the last TOC update. Set --insert as well. Default: false."
132+
assert_equal "${lines[12]}" " --skip-header Hide entry of the topmost headlines. Default: false."
133+
assert_equal "${#lines[@]}" "14"
134+
}
135+
121136
@test "--help" {
122137
run $BATS_TEST_DIRNAME/../gh-md-toc --help
123138
assert_success
124-
assert_equal "${lines[1]}" "Usage:"
125-
assert_equal "${lines[2]}" " gh-md-toc [--insert] [--hide-footer] [--skip-header] [--indent #spaces] src [src] Create TOC for a README file (url or local path)"
126-
assert_equal "${lines[3]}" " gh-md-toc [--no-backup] [--hide-footer] [--skip-header] [--indent #spaces] src [src] Create TOC without backup, requires <!--ts--> / <!--te--> placeholders"
127-
assert_equal "${lines[4]}" " gh-md-toc - Create TOC for markdown from STDIN"
128-
assert_equal "${lines[5]}" " gh-md-toc --help Show help"
129-
assert_equal "${lines[6]}" " gh-md-toc --version Show version"
139+
test_help
130140
}
131141

132142
@test "no arguments" {
133143
run $BATS_TEST_DIRNAME/../gh-md-toc
134144
assert_success
135-
assert_equal "${lines[1]}" "Usage:"
136-
assert_equal "${lines[2]}" " gh-md-toc [--insert] [--hide-footer] [--skip-header] [--indent #spaces] src [src] Create TOC for a README file (url or local path)"
137-
assert_equal "${lines[3]}" " gh-md-toc [--no-backup] [--hide-footer] [--skip-header] [--indent #spaces] src [src] Create TOC without backup, requires <!--ts--> / <!--te--> placeholders"
138-
assert_equal "${lines[4]}" " gh-md-toc - Create TOC for markdown from STDIN"
139-
assert_equal "${lines[5]}" " gh-md-toc --help Show help"
140-
assert_equal "${lines[6]}" " gh-md-toc --version Show version"
145+
test_help
141146
}
142147

143148
@test "--version" {

0 commit comments

Comments
 (0)