Skip to content

Update CLI to handle multiple arguments#137

Closed
ChrisWard42 wants to merge 1 commit intoekalinin:masterfrom
ChrisWard42:fix-processing-multiple-arguments
Closed

Update CLI to handle multiple arguments#137
ChrisWard42 wants to merge 1 commit intoekalinin:masterfrom
ChrisWard42:fix-processing-multiple-arguments

Conversation

@ChrisWard42
Copy link
Copy Markdown

If specifying multiple arguments to the script, only the first argument is properly consumed, the others are treated as input files and generate errors such as:

./gh-md-toc --insert --indent 2 NOTES.md > toc.md
rm: unrecognized option '--indent~~'
Try 'rm --help' for more information.

The present CLI handler only looks at the first argument $1 before proceeding. This updates the handler to process all defined CLI arguments until it sees an argument that doesn't match, at which point it treats the rest as input files. This also includes the fix for the --indent argument that was outlined here: #132

Existing tests passed when run locally:

make test
 ✓ TOC for local README.md
 ✓ TOC for local README.md with skip headers
 ✓ TOC for remote README.md
 ✓ TOC for mixed README.md (remote/local)
 ✓ TOC for markdown from stdin
 ✓ --help
 ✓ no arguments
 ✓ --version
 ✓ TOC for non-english chars, #6, #10
 ✓ TOC for text with backquote, #13
 ✓ TOC for text with plus signs, #100

11 tests, 0 failures

@ekalinin
Copy link
Copy Markdown
Owner

It looks like fixed in #132.

@ekalinin ekalinin closed this Jul 16, 2022
@ChrisWard42
Copy link
Copy Markdown
Author

ChrisWard42 commented Jul 17, 2022

@ekalinin This issue is not fixed by the fix merged in #132 . Re-tested after you merged that PR to verify. That was specifically about the "--indent" flag not working, this is about the CLI not accepting multiple arguments in a single command, indent just happens to be the one used in the example.

Against HEAD of main:

~/code/github-markdown-toc$ git rev-parse HEAD
435768259cb60e5842f7cde0679d495b3c31dfbd
~/code/github-markdown-toc$ ./gh-md-toc --insert --indent 2 README.md

rm: unrecognized option '--indent~~'
Try 'rm --help' for more information.
Parsing local markdown file requires access to github API
Please make sure curl is installed and check your network connectivity

Against my branch:

~/code/github-markdown-toc$ git checkout fix-processing-multiple-arguments 
Branch 'fix-processing-multiple-arguments' set up to track remote branch 'fix-processing-multiple-arguments' from 'origin'.
Switched to a new branch 'fix-processing-multiple-arguments'
~/code/github-markdown-toc$ ./gh-md-toc --insert --indent 2 README.md 

Table of Contents
=================

* [gh-md-toc](#gh-md-toc)
* [Table of contents](#table-of-contents)
* [Installation](#installation)
* [Usage](#usage)
  * [STDIN](#stdin)
  * [Local files](#local-files)
  * [Remote files](#remote-files)
  * [Multiple files](#multiple-files)
  * [Combo](#combo)
  * [Auto insert and update TOC](#auto-insert-and-update-toc)
  * [GitHub token](#github-token)
  * [TOC generation with Github Actions](#toc-generation-with-github-actions)
* [Tests](#tests)
* [Dependency](#dependency)
* [Docker](#docker)
  * [Local](#local)
  * [Public](#public)
Found markers

!! TOC was added into: 'README.md'
!! Origin version of the file: 'README.md.orig.2022-07-16_233559'
!! TOC added into a separate file: 'README.md.toc.2022-07-16_233559'


<!-- Created by https://github.com/ekalinin/github-markdown-toc -->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants