Skip to content

Commit 76c9a6c

Browse files
authored
Merge pull request #70 from jordantrizz/nobackup
Added Create TOC without backup option --ins-nb
2 parents 27b0f5a + b43bf68 commit 76c9a6c

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

gh-md-toc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ gh_toc(){
102102
local gh_src_copy=$1
103103
local gh_ttl_docs=$2
104104
local need_replace=$3
105+
local no_backup=$4
105106

106107
if [ "$gh_src" = "" ]; then
107108
echo "Please, enter URL or local path for a README.md"
@@ -174,9 +175,14 @@ gh_toc(){
174175
sed -i "/${ts}/r ${toc_path}" "$gh_src"
175176
fi
176177
echo
178+
if [ $no_backup = "yes" ]; then
179+
rm ${toc_path} ${gh_src}${ext}
180+
fi
177181
echo "!! TOC was added into: '$gh_src'"
178-
echo "!! Origin version of the file: '${gh_src}${ext}'"
179-
echo "!! TOC added into a separate file: '${toc_path}'"
182+
if [ -z $no_backup ]; then
183+
echo "!! Origin version of the file: '${gh_src}${ext}'"
184+
echo "!! TOC added into a separate file: '${toc_path}'"
185+
fi
180186
echo
181187
fi
182188
fi
@@ -231,6 +237,7 @@ gh_toc_app() {
231237
echo ""
232238
echo "Usage:"
233239
echo " $app_name [--insert] src [src] Create TOC for a README file (url or local path)"
240+
echo " $app_name [--no-backup] src [src] Create TOC without backup, requires <!--ts--> / <!--te--> placeholders"
234241
echo " $app_name - Create TOC for markdown from STDIN"
235242
echo " $app_name --help Show help"
236243
echo " $app_name --version Show version"
@@ -271,10 +278,15 @@ gh_toc_app() {
271278
shift
272279
fi
273280

281+
if [ "$1" = '--no-backup' ]; then
282+
need_replace="yes"
283+
no_backup="yes"
284+
shift
285+
fi
274286
for md in "$@"
275287
do
276288
echo ""
277-
gh_toc "$md" "$#" "$need_replace"
289+
gh_toc "$md" "$#" "$need_replace" "$no_backup"
278290
done
279291

280292
echo ""

tests/tests.bats

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,21 @@ load test_helper
9292
assert_success
9393
assert_equal "${lines[1]}" "Usage:"
9494
assert_equal "${lines[2]}" " gh-md-toc [--insert] src [src] Create TOC for a README file (url or local path)"
95-
assert_equal "${lines[3]}" " gh-md-toc - Create TOC for markdown from STDIN"
96-
assert_equal "${lines[4]}" " gh-md-toc --help Show help"
97-
assert_equal "${lines[5]}" " gh-md-toc --version Show version"
95+
assert_equal "${lines[3]}" " gh-md-toc [--no-backup] src [src] Create TOC without backup, requires <!--ts--> / <!--te--> placeholders"
96+
assert_equal "${lines[4]}" " gh-md-toc - Create TOC for markdown from STDIN"
97+
assert_equal "${lines[5]}" " gh-md-toc --help Show help"
98+
assert_equal "${lines[6]}" " gh-md-toc --version Show version"
9899
}
99100

100101
@test "no arguments" {
101102
run $BATS_TEST_DIRNAME/../gh-md-toc
102103
assert_success
103104
assert_equal "${lines[1]}" "Usage:"
104105
assert_equal "${lines[2]}" " gh-md-toc [--insert] src [src] Create TOC for a README file (url or local path)"
105-
assert_equal "${lines[3]}" " gh-md-toc - Create TOC for markdown from STDIN"
106-
assert_equal "${lines[4]}" " gh-md-toc --help Show help"
107-
assert_equal "${lines[5]}" " gh-md-toc --version Show version"
106+
assert_equal "${lines[3]}" " gh-md-toc [--no-backup] src [src] Create TOC without backup, requires <!--ts--> / <!--te--> placeholders"
107+
assert_equal "${lines[4]}" " gh-md-toc - Create TOC for markdown from STDIN"
108+
assert_equal "${lines[5]}" " gh-md-toc --help Show help"
109+
assert_equal "${lines[6]}" " gh-md-toc --version Show version"
108110
}
109111

110112
@test "--version" {

0 commit comments

Comments
 (0)