Skip to content

Commit c29d092

Browse files
committed
Added Create TOC without backup option --no-backup
1 parent 83fadb6 commit c29d092

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
@@ -96,6 +96,7 @@ gh_toc(){
9696
local gh_src_copy=$1
9797
local gh_ttl_docs=$2
9898
local need_replace=$3
99+
local no_backup=$4
99100

100101
if [ "$gh_src" = "" ]; then
101102
echo "Please, enter URL or local path for a README.md"
@@ -168,9 +169,14 @@ gh_toc(){
168169
sed -i "/${ts}/r ${toc_path}" "$gh_src"
169170
fi
170171
echo
172+
if [ $no_backup = "yes" ]; then
173+
rm ${toc_path} ${gh_src}${ext}
174+
fi
171175
echo "!! TOC was added into: '$gh_src'"
172-
echo "!! Origin version of the file: '${gh_src}${ext}'"
173-
echo "!! TOC added into a separate file: '${toc_path}'"
176+
if [ -z $no_backup ]; then
177+
echo "!! Origin version of the file: '${gh_src}${ext}'"
178+
echo "!! TOC added into a separate file: '${toc_path}'"
179+
fi
174180
echo
175181
fi
176182
fi
@@ -225,6 +231,7 @@ gh_toc_app() {
225231
echo ""
226232
echo "Usage:"
227233
echo " $app_name [--insert] src [src] Create TOC for a README file (url or local path)"
234+
echo " $app_name [--no-backup] src [src] Create TOC without backup, requires <!--ts--> / <!--te--> placeholders"
228235
echo " $app_name - Create TOC for markdown from STDIN"
229236
echo " $app_name --help Show help"
230237
echo " $app_name --version Show version"
@@ -265,10 +272,15 @@ gh_toc_app() {
265272
shift
266273
fi
267274

275+
if [ "$1" = '--no-backup' ]; then
276+
need_replace="yes"
277+
no_backup="yes"
278+
shift
279+
fi
268280
for md in "$@"
269281
do
270282
echo ""
271-
gh_toc "$md" "$#" "$need_replace"
283+
gh_toc "$md" "$#" "$need_replace" "$no_backup"
272284
done
273285

274286
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)