Repository navigation
Conversation
Currently `gh-md-toc` will only do a limited job parsing arguments. e.g. `gh-md-toc --insert --hide-footer --skip-header README.md` would fail as only the `--insert` option would be parsed as an option and the `--hide-footer` option would be considered the filename. This PR adds a new parser in a loop that will parse all arguments instead. The parser is inspired by https://stackoverflow.com/a/14203146, which solves the problem nicely.
ekalinin
left a comment
There was a problem hiding this comment.
Thanks for the PR. A few things need to be fixed before it can be merged:
-
Conflicts with master. The PR is based on 0.9.0, and master has since added
--depthand--numbered. The new loop has no cases for them, so they fall into the-*branch and print help. The--numberedchecks (type, and--indent3 or more forlist) also need to run after the loop. Please rebase and add both options. The tests for #25 and #26 cover them. -
--indentas the last argument hangs.gh-md-toc README.md --indentnever exits:shift 2fails without shifting, so the loop spins forever. Please check that the value is present. -
Unknown options print help and exit 0.
gh-md-toc --insert --indnet 2 README.mdexits 0, so a typo in CI passes silently while the TOC is never updated. It should print an error and exit non-zero. -
-is handled in the middle of parsing. The-)branch returns right away, so options after-are ignored, files before-are dropped, and--insert/--skip-headerbefore-do nothing.-should be collected as a source like any file and processed after the loop. -
make lintfails. The rewritten block brings back warnings fixed on master in 1c9e38a (SC2166, SC2006/SC2046, SC2155, SC2086, SC2162) and adds SC2317 and SC2221/SC2222. Keeping master's version of the stdin code after the rebase fixes most of them.
Currently
gh-md-tocwill only do a limited job parsing arguments.e.g.
gh-md-toc --insert --hide-footer --skip-header README.mdwould fail as only the--insertoption would be parsed as an option and the--hide-footeroption would be considered the filename.This PR adds a new parser in a loop that will parse all arguments instead.
The parser is inspired by https://stackoverflow.com/a/14203146, which solves the problem nicely.